草庐IT

C_LIBRARY_CALL_WHICH_RETURNS_NEW_

全部标签

javascript - new Date() 在 Chrome 或 Firefox 中显示不同的结果

奇怪的是,新的Date()会在不同的浏览器中产生不同的结果。在Chrome45.0.2454.101m中:newDate(2015,9,1)ThuOct01201500:00:00GMT+0200(W.EuropeDaylightTime)在Firefox40.0.3中(默认检查器/控制台)newDate(2015,9,1)Date2015-09-30T22:00:00.000Z附加信息如果我在Firefox中尝试使用FIREBUG扩展的控制台,它会像Chrome一样运行良好。发生了什么?似乎Firefox没有计算偏移量,实际上它比正确日期晚了2小时。我在其他工作站上做了测试,似乎都有

javascript - foo.toString() 和 Object.prototype.toString.call(foo) 有什么区别?

如果我定义一个函数:functionfoo(){alert(this.x);}我可以通过调用foo函数的toString方法来打印函数定义。console.log(foo.toString())输出:functionfoo(){alert(this.x);}如果我然后运行console.log(Object.prototype.toString.call(foo))输出:"[objectFunction]"令我惊讶的是输出结果不同。我认为这两种形式是等价的吗?即foo函数从顶级Object继承了toString方法并使用Object.prototype.toString.call(fo

javascript - 为什么要使用带参数的 Array.prototype.slice.call

我正在使用apply调用一个方法,但我不知道我将传递多少个参数:目前我的代码是这样的:selectFolder:function(e){e.preventDefault();this.addSelectedClass.apply(this,Array.prototype.slice.call(arguments));},我使用Array.prototype.slice的唯一原因是因为它在大多数示例中都是如此。为什么我不只是像这样传递参数:this.addSelectedClass.apply(this,arguments); 最佳答案

javascript - 为什么 "typeof + ' '"returns '号'?

让我们尝试在控制台中输入以下代码:typeof+''这会返回“number”,而没有参数的typeof本身会抛出错误。为什么? 最佳答案 unaryplusoperator在字符串上调用内部ToNumber算法。+''===0typeof+''//The`typeof`operatorhasthesameoperatorprecedencethantheunaryplusoperator,//buttheseareevaluatedfromrighttoleftsoyourexpressionisinterpretedas:type

javascript - 为什么要使用 Array.prototype.forEach.call(array, cb) 而不是 array.forEach(cb)?

我刚刚查看了今年ng-europesession的一些照片,并注意到一张幻灯片,我认为它可能显示了即将推出的Angular2的一些代码。请参见此处:(来源:https://plus.google.com/u/0/photos/+ThierryLAU/albums/6073085583895256529/6073092865671487010?pid=6073092865671487010&oid=105910465983441810901)我不明白的是:为什么此代码的作者使用Array.prototype.forEach.call(array,cb)而不是较短且(在我看来)等效的版本a

javascript - jQuery 事件按键 : Which key was pressed? A-Z, & @

在按下键时,我从jQuery得到以下内容:jQuery.EventaltKey:falseattrChange:undefinedattrName:undefinedbubbles:truebutton:undefinedcancelable:truecharCode:0clientX:undefinedclientY:undefinedctrlKey:falsecurrentTarget:HTMLDivElementdata:undefineddetail:0eventPhase:2fromElement:undefinedhandleObj:Objecthandler:functi

javascript - 使用 `new Function` 和性能问题

我正在通过AJAX加载一个脚本文件,并运行它的内容,我正在这样做:newFunction('someargument',xhr.responseText)(somevalue);但是,根据MDN:FunctionobjectscreatedwiththeFunctionconstructorareparsedwhenthefunctioniscreated.Thisislessefficientthandeclaringafunctionandcallingitwithinyourcode,becausefunctionsdeclaredwiththefunctionstatement

javascript - 为什么使用 .call(this) 而不是括号

这个问题在这里已经有了答案:Reasonbehindthisselfinvokinganonymousfunctionvariant(5个答案)关闭8年前。有没有什么特别的原因让我经常遇到:(function(){console.log("Hello");}).call(this);代替:(function(){console.log("Hello");})();传不传this调用应该是一样的效果吧?似乎有一些性能差异:http://jsperf.com/call-vs-parenthesis.

javascript - 为什么不能使用 .call() 调用 console.log

下面的代码返回一个带有“hello”的弹出窗口。alert.call(this,'hello');但是下面的代码返回错误“TypeError:Illegalinvocation”。console.log.call(this,'hello');alert和console.log的实现有什么区别? 最佳答案 alert是一个全局方法(window.alert)。如果你调用它alert.call(this),this就是窗口对象。因为log是console对象中的一个方法,它期望this是console对象本身,但是你还是用this(wi

javascript - "new new Something"如何在 JavaScript 中产生有效结果?

我目前正在开发一个JavaScript解析器并研究ECMAScript5.1specification.这是一个让我困惑的问题。§11.2Left-Hand-SideExpressions定义了以下NewExpression产生式:NewExpression:MemberExpressionnewNewExpression如果我没看错的话,NewExpression可能是这样的newnewSomething(实际上,任何数量的新。)这让我很困惑。newSomething怎么可能返回任何你可以再次new的东西?有可能吗? 最佳答案 它