我如何在匿名 javascript 中调用该函数? (TinyMce 示例)
我如何在该方法中调用 test() ?有可能吗?
(function() {
tinymce.create('tinymce.plugins.WrImagerPlugin', {
init : function(editor, url) {
editor.addCommand('mceWrImagerLink', function() {
//--> how can i refer to test() here?
});
},
test: function () {alert('test');}
}
});
tinymce.PluginManager.add('wr_imager', tinymce.plugins.WrImagerPlugin);
})();
How can i call test() inside that method? It's possible?
(function() {
tinymce.create('tinymce.plugins.WrImagerPlugin', {
init : function(editor, url) {
editor.addCommand('mceWrImagerLink', function() {
//--> how can i refer to test() here?
});
},
test: function () {alert('test');}
}
});
tinymce.PluginManager.add('wr_imager', tinymce.plugins.WrImagerPlugin);
})();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
test
设为常规函数并将其分配给对象,如下所示:或者,您可以保留对该对象的引用:
最后,在这种特定情况下,您应该能够简单地调用 <代码>tinymce.plugins.WrImagerPlugin.test()。
You can make
test
a regular function and assign it to the object, like this:Alternatively, you can keep a reference to the object:
Finally, in this specific case, you should be able to simply call
tinymce.plugins.WrImagerPlugin.test()
.您还可以在
init
方法中保留对this
的引用,该方法将在addCommand
闭包中可用:You can also keep a reference to
this
in theinit
method that will be available in theaddCommand
closure: