草庐IT

send_this_email

全部标签

javascript - nodejs - 这是哪个 "this"?

所以这是一个尴尬的问题,但我正在学习NodeJS,我有一个问题。在Java中,当我从对象调用方法时,this实例保持不变(如本例所示)。privateTestinst;publicTest(){inst=this;this.myFunction();}privatevoidmyFunction(){System.out.println(inst==this);}这会返回true(理论上,这是我头脑中的代码)。但是,在NodeJS中,当我尝试做类似的事情时失败了。varMyObject=function(){this.other=newOtherObject();this.other.o

javascript - Function.prototype.call 在严格模式之外改变 this 的类型;为什么?

varexample=function(){console.log(typeofthis);returnthis;};在严格模式下:example.call('test')#prints'string'否则,example.call('test')#prints'object'然而,console.log(example.call('test'))版画test(如你所料)为什么Function.call更改typeof'test'==='string'绑定(bind)到this里面example? 最佳答案 当使用call()并将t

javascript - Firebug 控制台窗口范围。为什么 "this"不总是相同的?

Firebug控制台作用域。为什么“这个”不总是一样的?不应该一直是“window”吗? 最佳答案 控制台中this的值将与当前正在执行的代码中this的值相同。考虑:-functionouter(){//thisiswindowvarx={n:12};varfn=function(){//thisisobject{n:12}alert(this.n);}fn.call(x);}...如果你在x={n:12}行打断点,切换到控制台你会发现this是窗口。但是,当您进入alert行时,控制台中的this是x变量持有的对象。IOW在执行

javascript - 我可以将 "this"作为参数传递给 javascript 中的另一个函数吗

我有这个:$('#sliderli').click(function(){varstepClicked=$(this).index();alert(stepClicked);if(stepClicked!=0){$('#cs_previous').removeClass('cs_hideMe');}else{$('#cs_previous').addClass('cs_hideMe');}$('li.cs_current').removeClass('cs_current');$($(this)).addClass('cs_current');moveToNextImage(stepC

javascript - JS : What is 'this' coercion? use-strict 和那个有什么关系?

我在网站上阅读了以下内容:Use-stricthasanadvantage.Iteliminatesthiscoercion.Withoutstrictmode,areferencetoathisvalueofnullorundefinedisautomaticallycoercedtotheglobal.Thiscancausemanyheadfakesandpull-out-your-hairkindofbugs.Instrictmode,referencingaathisvalueofnullorundefinedthrowsanerror.这到底是什么意思?use-strict

javascript - 试图在我的 javascript 代码中理解 "this"(一件事有效,另一件事无效)

我一直在尝试通过将一本书中的一些Jquery示例重构为javascript来学习javascript。在下面的代码中,我将点击监听器添加到选项卡,并在用户单击选项卡时使其变为事件状态。vartabs=document.querySelectorAll(".tabsaspan");varcontent=document.querySelectorAll("main.contentli");for(vartabNumber=0;tabNumber当我运行它时,它会返回一个未定义的错误。但是,我尝试用this.classList.add("active")替换tabs[tabNumber].

javascript - 在 JQuery 中,为什么 $(this) == $(this) 返回 false?

这个问题在这里已经有了答案:HowtodetermineequalityfortwoJavaScriptobjects?(82个回答)jQueryobjectequality(7个答案)关闭5年前。我在我的控制台中运行了以下行(一旦加载了jquery脚本),并收到了以下结果:$(this)>[Window]$(this)!=$(this)>true$(this)==$(this)>false$(this)===$(this)>false而且我不知道要采取什么步骤来弄清楚发生了什么。我的猜测是,有一些对象拥有一个基于时间的值,该值正在发生变化,但我想知道它是否有所不同。在此期间,我会尝试

javascript - Heroku: Node 应用程序抛出 "No default language could be detected for this app"错误

我正在学习NodeJS,我正在学习的类(class)有几个项目,按部分排列。我将所有项目都放在一个主文件夹下,这也是一个gitrepository.主文件夹中的每个子文件夹本身就是一个Node项目,包含package.json和node_modules中的相关依赖项。问题是当我试图将一个这样的文件夹(todo-api)中的Node应用程序推送到heroku时,我收到以下错误-remote:Compressingsourcefiles...done.remote:Buildingsource:remote:remote:!Nodefaultlanguagecouldbedetectedf

javascript - this.props.onPress 不是函数

我有一个HomePage.js,其中包含AboutUs按钮,当我单击该按钮时,我想显示AboutUs.js.HomePage.js显示正确,但是,当我单击按钮时,出现以下错误:this.props.onPress不是函数。(在'this.props.onPress(e)'中,'this.props.onPress'是Object的一个实例)我有App.jsimportReact,{Component}from'react';import{StackNavigator}from'react-navigation';importHomePagefrom'./HomePage';import

javascript - this 关键字不适用于箭头函数

这个问题在这里已经有了答案:Whatdoes"this"refertoinarrowfunctionsinES6?(10个答案)关闭3年前。我正在学习ES6,我只是想将我的ES5知识转换为ES6。这是我的ES5代码:functionclick(){this.className+='grab';setTimeout(()=>(this.className='remove'),0);};这是我的ES6代码:constclick=()=>{this.className+='grab';setTimeout(()=>(this.className='remove'),0);console.lo