jQuery:为什么以下不分配美元'$'?

时间:2013-04-15 08:08:37

标签: javascript jquery variable-assignment

在以下示例中,用户尝试在加载了jQuery的开发人员控制台中重新分配美元函数$

[18:39:57.071] $ = function(){"hello"}
[18:39:57.072] (function (){"hello"})
[18:40:00.367] $
[18:40:00.381] (function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    })

为什么美元函数$未重新定义?

1 个答案:

答案 0 :(得分:1)

也许您正面临“范围”问题,而您并未在“全球”范围内重新定义$

您可以尝试:window.$ = function(){"hello";}