我正在使用 Clojurescript 开发单页应用程序,我想使用 TinyMCE 作为某些字段的所见即所得编辑器。为了提高空间效率,我希望最终在高级模式下使用 google clojure 编译器来缩小项目。由于tinymce dev javascript 文件似乎不适合用作外部文件,因此我不得不编写自己的文件。
有一个特定的函数调用我无法正常工作。在 clojurescript 中,我调用:
(.setContent (.get js/tinymce id) cont)
我想它会编译成类似的东西:
tinymce.get(id).setContent(cont);
我在我的 extern 中尝试了许多不同的函数定义,但我不断收到错误:
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 中。
是否有编写外部函数来捕获这些链式函数调用的正确方法?或者有没有办法重写第一个代码片段,以便我的外部人员正确保留函数名称?提前致谢。
最佳答案
这一行:
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")
关于javascript - 用于嵌套函数的 Clojurescript Extern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794505/