Clojurescript Extern for Nested Function

Clojurescript Extern for Nested Function

本文关键字:Function Nested for Extern Clojurescript      更新时间:2023-09-26

我正在用Clojurescript开发一个单页应用程序,我想使用TinyMCE作为某些领域的所见即所得编辑器。为了节省空间,我想最终在高级模式下使用谷歌clojure编译器缩小项目。由于 tinymce dev javascript 文件似乎不适合用作 extern 文件,我被迫编写自己的文件。

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

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

我想它会编译成这样的东西:

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

我已经在我的外部尝试了许多不同的函数定义,但我不断收到一个错误:

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

这告诉我 setContent 被编译器遮挡了。我当前的 extern 文件如下所示:

//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 中。编辑 器。

有没有一种正确的方法来编写 extern 来捕获这些链式函数调用?或者有没有办法重写第一个代码片段,以便我的 extern 正确保留函数名称?提前谢谢。

这一行:

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")