草庐IT

call-hierarchy

全部标签

javascript - 为什么 (function() { return this; }).call ('string literal' ) 返回 [String : 'string literal' ] instead of 'string literal' ?

这是我在试验JS时的最新发现:(function(){returnthis;}).call('stringliteral');//=>[String:'stringliteral']inV8//=>String{"stringliteral"}inFF我在执行以下操作时偶然发现了这一点:(function(){returnthis==='stringliteral';}).call('stringliteral');//=>false谁能告诉我为什么函数内部的this不是作为第一个参数传递给call的正是?编辑1Whatisthedifferencebetweenstringprimi

javascript - [].forEach.call(...?

我非常喜欢像这样在nodeLists上使用forEach方法:varnodes=document.querySelectorAll(".foo");[].forEach.call(nodes,function(item){//dostuffwithitem});不过我想知道,这样做是否比常规方式需要更长的时间?例如for(vari=0;i 最佳答案 这是一个niceperformancecomparison.根据它,Array.forEach比本地for循环慢。 关于javascript

Javascript 使用 `apply()` 传递参数数组,但保留 `this` 对 `call()` 的引用

我需要结合JavaScript的call()和apply()方法的强大功能。我遇到的问题是call()保留了对this的正确引用,但是当我需要它作为函数参数发送时,将我拥有的参数数组作为数组发送.apply()方法在使用数组时将参数发送到函数就好了,但我不知道如何向它发送对this的正确引用,call()方法好像天生就可以访问。下面是我所拥有的代码的简化版本,它可能看起来毫无用处,但它是表达要点的好方法://ANOBJECTTHATHOLDSSOMEFUNCTIONSvarmain={};main.the_number=15;main.some_function=function(ar

javascript - Node : Wrapping entire script in a function call

我一直在用nodejs编写如下模块:module.exports=function(logger,db,external,constants){return{//something}}最近我团队中有人建议将整个脚本包装在一个函数中以避免变量的全局混淆,即像这样:(function(){'usestrict';module.exports=function(logger,db,external,constants){return{//something}}}());据我所知,这种做法通常用于客户端代码。但是在nodejs的服务器端,这是必需的吗?我认为在nodejs中确实没有全局作用域,

javascript - 未捕获的异常 : cannot call methods on tabs prior to initialization

我正在使用以下代码更改点击时的标签颜色$("ul.tabs").tabs(">.pane");但是它抛出错误uncaughtexception:cannotcallmethodsontabspriortoinitialization;attemptedtocallmethod'>.pane'谁能帮我解决这个错误是什么? 最佳答案 如异常所述,它非常简单。您必须先初始化选项卡,然后才能对其进行处理。所以初始化它们。function(){$("ul.tabs").tabs();}或者简单地使用$("ul.tabs").tabs().ta

javascript - Angular 2 : setTimeout only called once

我正在Angular2中实现需要使用setTimeout的功能。我的代码:publicngAfterViewInit():void{this.authenticate_loop();}privateauthenticate_loop() {setTimeout(()=>{console.log("HellofromsetTimeout");},500)}setTimeout由ngAfterViewInit启动,但循环只执行一次,例如。“HellofromsetTimeout”只打印一次。问题:如何更改代码以使setTimeout起作用? 最佳答案

javascript - window.toString.call 在 IE8 中未定义

当你运行时:window.toString.call("")在FF/CH中一切正常,但在IE8中出现脚本错误。进一步调查发现,window.toString.call在IE8中未定义?你也可以运行这个:window.toStringinstanceofFunction;//falsealert(window.toString);//functiontoString(){//[nativecode]//}这是为什么以及如何解决它?我开始想知道jQuery最初是如何工作的? 最佳答案 window是一个宿主对象,ECMAScriptLa

javascript - AngularJs 指令 : call method from parent scope within template

我对Angular指令还很陌生,我很难让它做我想做的事。这是我所拥有的基础知识:Controller:controller('profileCtrl',function($scope){$scope.editing={'section1':false,'section2':false}$scope.updateProfile=function(){};$scope.cancelProfile=function(){};});指令:directive('editButton',function(){return{restrict:'E',templateUrl:'editbutton.t

javascript - handlebars.js 未捕获类型错误 : Object #<Object> has no method 'call'

有人帮忙解决handlebars.js的问题吗?我正在使用在Centos6.4上运行的handlesbars预编译模板。要安装这个,我安装了:npm:yum-y--enablerepo=epelinstallnpm首先继承以避免问题:npminstall-ginherits然后是Handlebars本身:npminstall-ghandlebars这给出了以下版本:handlebars@2.0.0-alpha.1/usr/lib/node_modules/handlebars乐观主义者@0.3.7(wordwrap@0.0.2)uglify-js@2.3.6(async@0.2.10,

javascript - rails : JS Controller Being Called Twice for Some Reason

出于某种原因,当我单击一个按钮时,我的Controller和生成的jquery函数被调用了两次。由于调用的js函数是toggle,这是一个问题,因为它会导致代码跳入和跳出View。这是表格:UnseenNotifications:"seen",:controller=>"notifications"},:remote=>true%>这是Controller:defseenrespond_todo|format|format.jsendend这里是jquery:$("div#notifications").toggle();$("div#count").html("'notificati