我已经搜索了关于此的文档的高低,但我在任何地方都找不到任何东西.
我正在使用Aloha并希望使用他们的侧边栏原型来创建我自己的新侧边栏,附加到其他插件功能.
他们的sidebar.js从这开始,但我不能为我的生活找到任何解释它意味着什么的文档.
define( [
'aloha/core',
'aloha/jquery',
'aloha/selection'
], function (Aloha, jQuery, Selection, Plugin) {
Run Code Online (Sandbox Code Playgroud)
然后它继续在那个包装器中定义一堆函数,所以vars
还有一些proptotypes
- 我可以解决这个问题......
那是什么说法或在哪里可以找到解释?
我看到这在JavaScript中一直被使用:
define(['param1', 'param2'], function() {
});
Run Code Online (Sandbox Code Playgroud)
功能是什么define
?
我知道define用于定义一个模块,而function是一个匿名函数,但是函数中的参数“require”是什么?
如果我在 中写任何东西define(function(require){...})
,什么时候会调用它?如何调用他的匿名函数?
请帮忙,我是高级 JS 的新手。
您是否可以在使用严格模式时获得全局范围,并确保您可以在非窗口环境中运行.
看这些例子:
define(['other', 'thing'], function() {
// this === window in desktop environment
// this === GLOBAL in node environment
});
define(['other', 'thing'], function() {
"use strict";
// this === undefined in desktop environment
// this === GLOBAL in node environment
// As of my understanding node has to be configured using `node --use_strict`
// (http://stackoverflow.com/questions/9031888/any-way-to-force-strict-mode-in-node)
// But that not the point.
});
Run Code Online (Sandbox Code Playgroud)
有没有办法让内部的全局变量(window
/ GLOBAL
)define
.
javascript scope global-variables requirejs requirejs-define