【问题标题】:What makes these two require.js calls different from each other?是什么让这两个 require.js 调用彼此不同?
【发布时间】:2014-08-12 02:13:07
【问题描述】:

我目前正在试验Hot Towel SPA Template,如果我理解正确的话,它会为 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 and then register them with require as follows: 
define('jquery', function () { return jQuery; });
define('knockout', ko);

define('knockout', function () => { return ko; });? 也会这样做吗?

【问题讨论】:

    标签: javascript jquery knockout.js requirejs hottowel


    【解决方案1】:

    在前者的情况下,我们定义了一个名为“jquery”并在全局命名空间中定义的模块。

    在后者的情况下,我们定义了一个模块,该模块的引用在 require 路径中定义。

    这两种情况的效果是一样的。 Hot Towel 的创建者 John Papa 建议不要使用 require 定义第三方模块。相反,只有自己的模块应该以这种方式定义。当然,jQuery 和 Knockout 在 Durandal 框架中是例外,因为它们是 Durandal 框架的一部分

    但是,John 给出该建议的原因在于第三方框架设计的所有技术细节。有时你必须垫片,有时不需要。有时您必须返回窗口上定义的内容,有时则不需要。有时会有顺序依赖,或辅助库依赖(反过来,它们有自己的特性)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多