草庐IT

this-is-a-collection

全部标签

javascript - IE8 Array.prototype.slice : 'this' is not a JavaScript object

我只在IE8中收到此错误消息,我不知道如何转换现有函数以兼容IE8。_initEvents:function(){varself=this;Array.prototype.slice.call(this.menuItems).forEach(function(el,i){vartrigger=el.querySelector('a');if(self.touch){trigger.addEventListener('touchstart',function(ev){self._openMenu(this,ev);});}else{trigger.addEventListener('cl

javascript - 试图找出一些js代码中的 'this'

functionbuttonClicked(){vartext=(this===window)?'window':this.id;console.log(text);}varbutton1=document.getElementById('btn1');varbutton2=document.getElementById('btn2');button1.onclick=buttonClicked;button2.onclick=function(){buttonClicked();};问题:点击button1,显示:btn1,点击button2和button3,显示:window,为什

javascript - 为什么 "this"的值会改变。?

我正在学习javascript,我遇到了一个疑问。为什么“this”的值在第一个示例中未定义,但在第二个示例中打印正确。示例1:varmyNamespace={myObject:{sayHello:function(){console.log("nameis"+this.myName);},myName:"john"}};varhello=myNamespace.myObject.sayHello;hello();//"nameisundefined"示例2:varmyNamespace={myObject:{sayHello:function(){console.log("Hi!My

javascript - 调用 $(this) 时,jQuery 会重新查询 DOM 吗?

在下面的代码中,当$(this)被调用时,jQuery是否重新查询DOM,就好像选择器已传递给它一样(使用对象的某些属性作为选择器),或者jQuery是否保留先前返回的对象?$('.someButton').on('click',function(){$(this).remove();//Isthisanotherlookup,orjustawrapperforthepreviouslyreturnedobject?}); 最佳答案 它不会重新查询DOM,this已经是一个元素。jQuery只是将上下文设置为元素,调整长度,然后返回

javascript - JQuery $(this) 在函数参数中不起作用

以下代码无效:$(".countdown").circularCountdown({startDate:$(this).attr('data-start'),endDate:$(this).attr('data-end'),timeZone:$(this).attr("timezone")});下面那个工作正常,$(".countdown").circularCountdown({startDate:$(".countdown").attr('data-start'),endDate:$(".countdown").attr('data-end'),timeZone:$(".count

javascript - 从远程 repo 中拉出并获得 : "Parsing error: The keyword ' import' is reserved"

我收到以下错误:ERRORin./src/main.jserrorParsingerror:Thekeyword'import'isreserved/Users/staging/Desktop/sourcetree/viewer_web/src/main.js:1:1importVuefrom'vue'出于某种原因,我的项目中的ES6功能未被识别?我正在使用Node5.0,这是我的package.json:{"name":"istaging-viewer","description":"AVue.jsproject","author":"Alex","private":true,"sc

javascript - "this"上下文输出无法理解

我很难理解下面的代码。functionfoo(){console.log(this.a);}varobj={a:2,foo:foo};vara=4;obj.foo();setTimeout(obj.foo,100);setTimeout(obj.foo.bind(obj),100);它的输出为2、4、2,我无法理解。 最佳答案 第一种情况,obj.foo();foo中的this将指向obj,因为您已将该函数分配为该特定对象的属性。第二种情况,setTimeout(obj.foo,100);在setTimeout中,传递的函数将在窗口

javascript - 云函数 : How to copy Firestore Collection to a new document?

我想在发生事件时使用CloudFunctions在Firestore中制作一个集合的副本我已经有了迭代集合并复制每个文档的代码constfirestore=admin.firestore()firestore.collection("products").get().then(query=>{query.forEach(function(doc){varpromise=firestore.collection(uid).doc(doc.data().barcode).set(doc.data());});});有更短的版本吗?一次复制整个集合? 最佳答案

javascript - 防止 this.state 与 setState 一起使用

Thereference状态:setState()doesnotalwaysimmediatelyupdatethecomponent.Itmaybatchordefertheupdateuntillater.Thismakesreadingthis.staterightaftercallingsetState()apotentialpitfall.Instead,usecomponentDidUpdateorasetStatecallback(setState(updater,callback)),eitherofwhichareguaranteedtofireaftertheupd

javascript - How to implement a Client-side Ajax Login on Asp.Net MVC (A link to the solution for Asp.Net Webforms is in here)

我正在尝试在Asp.NetMVC上实现客户端ajax登录。我以前在WebForms上设置得很好,但现在我已经转移到MVC上,这给我带来了一些麻烦。如果您想要有关Asp.NetWebforms的客户端Ajax登录的教程,可以找到here--简单,A++现在...出于某种原因,它不适用于Asp.NetMVC。除了执行ssa.login()时,我使用了与Webforms完全相同的教程(等效于:Sys.Services.AuthenticationService.login())它什么也没做。我在onLoginComplete()函数和onError()函数中都有警报。在ssa.login被调