【发布时间】:2018-11-29 21:41:26
【问题描述】:
如何调用定义在匿名函数内部但都在同一个 JS 文件中的函数。这是我的代码 sn-p。如何从testMethodOutside()调用_testMethodInside()?
// Line 1 to 13 is an existing code from ESRI API
define([
"dojo/_base/declare",
"dojo/_base/html"
], function (
declare,
html
) {
return declare([_WidgetBase, _TemplatedMixin], {
_testMethodInside: function () {
return 'success';
}
});
});
//Call above using this function
function testMethodOutside(){
//How to call _testMethodInside() function from here
}
【问题讨论】:
-
为什么要实现这样的事情?
-
@BooBerr'ita,第 1 到 13 行是 ESRI API 的现有代码。我想使用我的
testMethodOutside()调用该方法 -
这称为AMD format,是定义模块的一种流行方式。您可以将它们与
require一起使用,并且您应该有一个声明define和require的模块加载器库。
标签: javascript dojo amd js-amd esri-javascript-api