有时候Javascript代码在步入(F11)时不会执行?

时间:2015-02-28 03:57:39

标签: javascript

代码如下: 在行旁边设置断点(断点1,断点2)。



if (!TestSolution)
{
    var TestSolution= {};
}

TestSolution.Utils = TestSolution.Utils || {};

var dummy_ = (function ()
{
    // Sometimes step into the line just pop out. 
    // The following lines will not run. 
    **var self = this;**   // Break point 1. 

    // Subscribe to event optionally unsubscribing first.
    **this.Subscribe = function(source, eventName, handler, unsubscribe)** // Break point 2.
    {
        // By default - always unsubscribe first - there is hardly a reason to have
        // multiple subscriptions for the same combination of controls and events.
        if (!(unsubscribe === false)) $(source).off(eventName, handler);
        $(source).on(eventName, handler);
    }
}).call(TestSolution.Utils);




问题是,有时候它会进入突破点1,而当按F11时,它并没有进入突破点2.我觉得" var self = this;"没有运行。它只是弹出功能。

编辑:这是在Chrome(版本41.0.2243.0(64位))中调试的。

1 个答案:

答案 0 :(得分:0)

此代码块非常奇怪,可能会导致竞争问题:

if (!TestSolution)
{
    var TestSolution= {};
}

我会把它改成

var TestSolution = TestSolution || {};