草庐IT

send_this_email

全部标签

javascript - Coffeescript 中的 var self = this

我在使用Coffeescript时遇到了一些范围问题。drawFirstLine:(currentAngle)->currentAngle=currentAngle#=1switch@type#set@endAngletopickuplateron#Math.PI*2istheendpointofacircledividedbysecondstimescurrentsecondswhen"seconds"then@endAngle=Math.PI*2/60*@secondswhen"minutes"then@endAngle=Math.PI*2/60*@minuteswhen"hour

javascript - 如何在不在外部缓存的情况下将 'this' 传递给 Promise?

这个问题在这里已经有了答案:Howtoaccessthecorrect`this`insideacallback(13个答案)关闭3年前。我有一个名为LangDataService.isDataReady的变量,它是一个等待解决的Promise。解决后会发生一些逻辑。我怎样才能将它传递给那个Promise?LangDataService.isDataReady.then(function(){this.modalOn()});我知道我可以缓存varself_=this;但我对其他替代方案感到好奇?

Javascript 'this' 与对象名称

一个好奇的问题,如果我有以下代码,通过this而不是user调用属性有什么好处(不仅仅是简单)show_name方法?varuser={name:'JohnDoe',show_name:function(){alert(this.name);//ORalert(user.name);}}; 最佳答案 如果你看一下这个例子,区别就很明显了。它创建第二个对象并相应地设置原型(prototype)。varuser={name:'JohnDoe',show_name:function(){alert(this.name);//ORalert

javascript - 如何使用调用函数的元素的 "this"引用?

例如,我想要一个被许多元素使用的函数来获取调用元素的属性。functionexample(){varname=//nameofthecallingelement"$(this).attr('name')"}Button1Button2因此,如果名为“somename1”的按钮调用该函数,则变量“name”将被分配给“somename1”,因此如果“somename2”调用它,它将被分配给“somename2” 最佳答案 使用这个:functionexampleFunction(exampleElement){varname=exam

javascript - 为什么不将 this.parent() 定义为函数?

JSFiddle我正在创建一个新的按钮元素$('RemoveEntry',{'type':'button','class':'delete_button'});然而,type或class属性似乎都没有定义,并且控制台打印出一条错误消息,指出this.parent()is不是函数(虽然我肯定我启用了jquery)恐怕我做了一些简单而愚蠢的事情,但我似乎找不到任何错误。 最佳答案 没有在元素上设置属性的原因是您混合使用了jQuery方法。要以使用对象作为属性的方式使用该方法,第一个参数应该是单个标记,而不是HTML片段:$('',{'t

javascript - this.$root.$emit 在 Vue 中不起作用

我想在根组件上发出一个事件,并在根组件中监听。在子组件的子组件中,我这样做:this.$root.$emit('access-token',accessToken);在根组件(顶级组件,第一个加载)中我这样做(编辑:这是在mounted()方法中):this.$on('access-token',this.setAccessToken);虽然它不会对事件使用react。为什么? 最佳答案 您没有为事件$on使用$root改变这个:this.$on('access-token',this.setAccessToken);为此:this

javascript - JSLint 验证错误 "combine this with the previous var statement"

JSLint验证错误“将此与前面的var语句结合起来”我如何结合使用它才不会出现JSLint验证错误?我在getClassName函数的代码行中收到验证错误。$(document).ready(function(){'usestrict';//ThisfunctionisusedtocalculatethedatefunctiondateString(dateToDisplay){varmonthNames=['January','February','March','April','May','June','July','August','September','October','

javascript - 为什么 javascript this.style[property] 返回一个空字符串?

这个问题在这里已经有了答案:HowtoretrievethedisplaypropertyofaDOMelement?(4个答案)关闭7年前。为什么this.style[property]得到一个空字符串?我的代码是:Demo#test{height:100px;}.tclass{width:100px;}function$(ID){varelement=document.getElementById(ID||'nodId');if(element){element.css=css;}returnelement;}functioncss(prop,value){if(value==nu

javascript - JS : Why Is This Slower? 它不应该测试其他 OR 条件但它确实如此?

我刚刚测试了一些东西。我一直认为在OR条件下,一旦计算机/浏览器发现某些东西是真的,它就会返回它并且不会测试其他条件。我围绕这个假设构建了我的代码。但是,我对它进行了计时,看起来长测试花费了x4倍,对此有什么解释吗?注意:已在GoogleChrome控制台中测试。JSPerf:http://jsperf.com/or-condition返回真||1http://jsperf.com/or-condition2var条件=真||1;返回条件;http://jsperf.com/or-condition3if(true||1)returntrue好像比较快编辑:我刚刚发现true之后的条件

javascript - polymer 1.0 : Multiple calls to send() method of iron-request

我有一个使用实例的组件从后端检索数据,我想使用发送更新,例如POST/DELETE请求。第一次一切都完美无缺。但是,如果再次调用请求,则会出现错误:UncaughtTypeError:Cannotreadproperty'then'ofundefined我的模板定义如下所示:......在我的组件脚本中,我使用了send()的方法|发送POST:varme=this;this.$.xhr.send({url:"/cart-api",method:"POST",body:JSON.stringify(entry)}).then(function(){me._refresh();},fun