RequireJS&QUOT之前回调;确定"函数被调用? [英] Callback before RequireJS "define" function is called?

查看:192
本文介绍了RequireJS&QUOT之前回调;确定"函数被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的骨干,我帮助维持有大量的骨干网和RequireJS code,做一些像这样的应用程序:

I'm new to Backbone, and i'm helping to maintain an app that has lots of Backbone and RequireJS code that does something like so:

define(

    ['backbone', 'underscore'],

    function(Backbone, _) {
      // some code here
    }
);

我想配置下划线在这些页面中,...在最简单的意义上说,我可以做一些像这样:

I'd like to configure Underscore in each of these pages... In the most simple sense, I could just do something like so:

define(

    ['backbone', 'underscore'],

    function(Backbone, _) {

      // do some stuff to configure underscore
      configureUnderscore(_);

    }
);

但我想独自离开每个页面的定义功能,只是注入了的前定义回调被调用。

but I'd like to leave each page's define function alone, and just inject a callback that's called before the define callback is called.

这怎么能与骨干网或RequireJS办?

How can this be done with Backbone or RequireJS?

推荐答案

下面是如何使这项工作在这个另外一个答案页面,并从复制这个StackOverflow的答案以一个类似的问题:

Here's how to make this work as suggested in another answer on this page, and copied from this StackOverflow answer to a similar question:

requirejs.config({
    paths: {
        'underscore': 'underscoreConfig',
        'originalUnderscore': 'underscore'
    },
    shim: {
        'originalUnderscore': {
            exports: '_'
        }
    }
});

underscoreConfig.js

define(['originalUnderscore'], function(_) {
    _.templateSettings =
    {
        evaluate    : /<%([\s\S]+?)%>/g,
        interpolate : /<%cleanHtml([\s\S]+?)%>/g,
        escape      : /<%[=-]([\s\S]+?)%>/g
    };
    return _;
});

这篇关于RequireJS&QUOT之前回调;确定&QUOT;函数被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆