Javascript 是什么使这两个require.js调用彼此不同?
我目前正在试验,若我理解正确的话,它为Durandal定义了这两个库。不过,我不知道这两个电话的确切区别:Javascript 是什么使这两个require.js调用彼此不同?,javascript,jquery,knockout.js,requirejs,hottowel,Javascript,Jquery,Knockout.js,Requirejs,Hottowel,我目前正在试验,若我理解正确的话,它为Durandal定义了这两个库。不过,我不知道这两个电话的确切区别: // Durandal 2.x assumes no global libraries. It will ship expecting // Knockout and jQuery to be defined with requirejs. .NET // templates by default will set them up as standard script // libs
// Durandal 2.x assumes no global libraries. It will ship expecting
// Knockout and jQuery to be defined with requirejs. .NET
// templates by default will set them up as standard script
// libs and then register them with require as follows:
define('jquery', function () { return jQuery; });
define('knockout', ko);
define('knockout',function()=>{return ko;})代码>是否执行相同操作?对于前者,我们定义了一个名为“jquery”的模块,该模块在全局命名空间中定义
对于后者,我们定义了一个模块,其引用在require路径中定义
这两种情况的效果相同。热毛巾的创建者John Papa建议不要使用require定义第三方模块。相反,只能用这种方式定义自己的模块。当然,jQuery和Knockout是Durandal框架中的例外,因为它们是Durandal框架的一部分
但是John给出建议的原因是由于第三方框架设计的所有技术细节。有时你必须填隙,有时不能。有时您必须返回窗口上定义的内容,有时则不返回。有时存在顺序依赖项或辅助库依赖项(它们又有自己的特性)