草庐IT

this-reference

全部标签

jquery - 为什么在 jQuery 插件中返回 this.each(function())?

我看到的一些开发jQuery插件的教程和例子倾向于回归this.each(function(){//Plugincodehere});在实例化插件的函数末尾,但我还没有看到它背后的任何推理,它似乎只是每个人都遵循的标准。谁能告诉我这种做法背后的原因?编辑:为了澄清,我的问题不是关于为什么要返回这个,而是为什么插件应该返回this.each。 最佳答案 当您使用选择器($('.myclass'))过滤元素时,它可以匹配多个元素。使用each,您可以遍历所有匹配的元素,您的代码将应用于所有这些元素。

jquery - 为什么在 jQuery 插件中返回 this.each(function())?

我看到的一些开发jQuery插件的教程和例子倾向于回归this.each(function(){//Plugincodehere});在实例化插件的函数末尾,但我还没有看到它背后的任何推理,它似乎只是每个人都遵循的标准。谁能告诉我这种做法背后的原因?编辑:为了澄清,我的问题不是关于为什么要返回这个,而是为什么插件应该返回this.each。 最佳答案 当您使用选择器($('.myclass'))过滤元素时,它可以匹配多个元素。使用each,您可以遍历所有匹配的元素,您的代码将应用于所有这些元素。

jquery - 类方法中的 Typescript "this"

我知道这可能是非常基础的,但我很难理解它。classMain{constructor(){requestAnimationFrame(this.update);//fine}update():void{requestAnimationFrame(this.update);//error,becausethisiswindow}}看来我需要一个代理,所以假设使用JqueryclassMain{constructor(){this.updateProxy=$.proxy(this.update,this);requestAnimationFrame(this.updateProxy);//

jquery - 类方法中的 Typescript "this"

我知道这可能是非常基础的,但我很难理解它。classMain{constructor(){requestAnimationFrame(this.update);//fine}update():void{requestAnimationFrame(this.update);//error,becausethisiswindow}}看来我需要一个代理,所以假设使用JqueryclassMain{constructor(){this.updateProxy=$.proxy(this.update,this);requestAnimationFrame(this.updateProxy);//

jquery - 在jQuery事件中控制 'this'的值

我使用jQuery创建了一个“控件”,并使用jQuery.extend来帮助使其尽可能面向对象。在我的控件初始化过程中,我像这样连接了各种点击事件jQuery('#availableinput',this.controlDiv).bind('click',this,this.availableCategoryClick);请注意,我将“this”作为绑定(bind)方法中的数据参数。我这样做是为了能够获取附加到控件实例的数据,而不是从触发单击事件的元素中获取的数据。这很完美,但我怀疑有更好的方法过去使用过Prototype,我记得一种绑定(bind)语法,它允许您控制事件中'this'

jquery - 在jQuery事件中控制 'this'的值

我使用jQuery创建了一个“控件”,并使用jQuery.extend来帮助使其尽可能面向对象。在我的控件初始化过程中,我像这样连接了各种点击事件jQuery('#availableinput',this.controlDiv).bind('click',this,this.availableCategoryClick);请注意,我将“this”作为绑定(bind)方法中的数据参数。我这样做是为了能够获取附加到控件实例的数据,而不是从触发单击事件的元素中获取的数据。这很完美,但我怀疑有更好的方法过去使用过Prototype,我记得一种绑定(bind)语法,它允许您控制事件中'this'

jquery - TypeScript 中是否有 'this' 的别名?

我试图用TypeScript编写一个类,该类定义了一个方法,该方法充当jQuery事件的事件处理程序回调。classEditor{textarea:JQuery;constructor(publicid:string){this.textarea=$(id);this.textarea.focusin(onFocusIn);}onFocusIn(e:JQueryEventObject){varheight=this.textarea.css('height');//在onFocusIn事件处理程序中,TypeScript将“this”视为类的“this”。但是,jQuery覆盖了thi

jquery - TypeScript 中是否有 'this' 的别名?

我试图用TypeScript编写一个类,该类定义了一个方法,该方法充当jQuery事件的事件处理程序回调。classEditor{textarea:JQuery;constructor(publicid:string){this.textarea=$(id);this.textarea.focusin(onFocusIn);}onFocusIn(e:JQueryEventObject){varheight=this.textarea.css('height');//在onFocusIn事件处理程序中,TypeScript将“this”视为类的“this”。但是,jQuery覆盖了thi

TypeError: this.getOptions is not a function 的解决

 一、问题的出现:在进行 React /vue项目开发的时候,出现了这个错误:TypeError:this.getOptionsisnotafunction,如下所示: 二、问题的分析:        这个实际上就是sass-loader的版本过高或过低,与当前node版本不对应,不兼容getOptions函数方法,所以需要对sass-loader进行升级或降级处理。三、解决方案1、命令行卸载node-sass和sass-loader,重新安装跟你当前node版本对应的node-sass和sass-loader。npmuninstallnode-sasssass-loadernpminstal

javascript - 未捕获的 NotFoundError : Failed to execute 'insertBefore' on 'Node' : The node before which the new node is to be inserted is not a child of this node

我在使用JavaScript时遇到问题。我收到此错误消息:UncaughtNotFoundError:Failedtoexecute'insertBefore'on'Node':Thenodebeforewhichthenewnodeistobeinsertedisnotachildofthisnode.Javascript:varvidCounter=0;vidCounter++;varoriginalDiv;varnewVideo=document.createElement("video");newVideo.setAttribute("name",vidCounter);new