【问题标题】:Clojurescript Extern for Nested FunctionClojurescript Extern 用于嵌套函数
【发布时间】:2016-04-25 03:43:21
【问题描述】:

我正在使用 Clojurescript 开发单页应用程序,并且我想将 TinyMCE 用作某些领域的 WYSIWYG 编辑器。为了空间效率,我想最终在高级模式下使用 google clojure 编译器来缩小项目。由于 tinymce dev javascript 文件似乎不适合用作外部文件,因此我不得不自己编写。

有一个特定的函数调用我无法开始工作。在clojurescript中,我调用:

(.setContent (.get js/tinymce id) cont)

我想它会编译成这样的:

tinymce.get(id).setContent(cont);

我在我的 externs 中尝试了许多不同的函数定义,但我一直收到错误:

TypeError: tinymce.get(...).Tl is not a function

这告诉我 setContent 被编译器掩盖了。我当前的外部文件如下所示:

//all seems to be well here...
var tinymce;
tinymce.get = function(name){};
tinymce.remove = function(node){};
tinymce.init = function(editor){};
tinymce.on = function(name, callback, prepend, extra){};


//tinymce setContent attempts
var tinymce.Editor;
tinymce.Editor.prototype.setContent = function(content){};
tinymce.Editor.setContent = function(content){};
tinymce.get(name).setContent = function(content){};
tinymce.get(name).prototype.setContent = function(content){};

var Editor;
Editor.prototype.setContent = function(content){};
Editor.setContent = function(content){};

目前这是一种将所有东西都扔到墙上然后看什么东西的尝试。 get(name) 返回的对象应该在命名空间 tinymce.Editor 中。

是否有适当的方法来编写外部函数来捕获这些链式函数调用?或者有没有办法重写第一个代码 sn-p 以便我的外部人员正确保留函数名称?提前致谢。

【问题讨论】:

    标签: javascript interop clojurescript


    【解决方案1】:

    这一行:

    var tinymce.Editor;
    

    在 JS 中语法不正确:

    SyntaxError: missing ; before statement
    

    删除它并留下这一行:

    tinymce.Editor.prototype.setContent = function(content){};
    

    这应该可以正常工作。

    此外,您可能总是回退到通过永远不会被重命名的字符串文字访问属性:

    (require '[goog.object :as gobj])
    (gobj/get your-object "i-wont-be-renamed")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 2021-11-03
      • 1970-01-01
      • 2022-08-17
      • 2021-03-26
      相关资源
      最近更新 更多