草庐IT

this_and_that

全部标签

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 - "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 - ES6 模块 : Exporting and importing performance differences

我的vue项目中有一些组件。我不喜欢importloaderfrom'@/components/someComponent1/someComponent1.vue';因为要写的东西很多而且我必须为每个组件重复一遍。所以我为components文件夹写了一个index.js:export{defaultassomeComponent1}from'./someComponent1/someComponent1.vue';export{defaultassomeComponent2}from'./someComponent2/someComponent2.vue';...这将允许我在一行中导

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

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

javascript - 为什么是 { : y = 1 } = { b: 2 } valid and { a: 1 } = { b: 2 } a SyntaxError?

我不明白为什么这两个JS表达式不等价为了在JS上做得更好,我正在尝试一些javascript表达式。这是我的最新发现:{a:y=1}={b:2}//{b:2}{a:1}={b:2}//UncaughtSyntaxError:Unexpectedtoken=谁能帮我理解一下? 最佳答案 首先,这不是destructuringassignmentswithoutdeclarations的正确语法.Theparentheses(...)aroundtheassignmentstatementarerequiredwhenusingobje

javascript - 停止在临时变量中保存 'this'

我一直不得不将this保存在一个临时变量中,以便在其他函数中访问它。例如,在下面的两个方法中,我将this保存在that变量中:startTimer:function(){varthat=this;if($('#defaultCountdown:hidden'))$('#defaultCountdown').show('slow');shortly=newDate();shortly.setSeconds(shortly.getSeconds()+5);$('#defaultCountdown').countdown('change',{until:shortly,layout:'Ne

javascript - 范围对象 : differences between Webkit and Mozilla based browsers

目前,我在为基于Mozilla和Webkit的浏览器编写抽象层以使用DOM范围对象(获取和处理用户选择)时遇到了一些麻烦。我也尝试过查看像Rangy这样的框架,但这对我的任务来说似乎太复杂了(我不知道在代码中的确切位置可以找到我需要的信息。如果有人能给我提示,我将不胜感激!)。我想要的就是这样:取回对选择开始的文本节点的引用及其偏移量取回对选择结束的文本节点的引用及其偏移量到目前为止,我的层看起来像这样:varSEL_ABSTR={get_selection:function(window_object){returnwindow_object.getSelection();},get

javascript - jquery 在自定义函数中使用 (this)

我创建了一个小的jquery脚本,但在自定义函数中使用(this)时遇到问题。这是代码:jQuery("li").click(function(){varscrollTop=jQuery(window).scrollTop();if(scrollTop>0){jQuery('html,body').animate({scrollTop:0},'slow',function(){fadeItems();});}else{fadeItems();}});functionfadeItems(){varslogan=jQuery(this).children('p').html();jQuer

javascript : how to distinguish between selected element list and form

这是脚本:http://jsbin.com/itusut/6/edit你好,我有功能:functionon(t,e,f){if(e.length){varl=e.length,n=0;for(;n如果我们这样做varhandle=document.getElementsByClassName('some-class');然后handle是一个节点列表。如果我们这样做varhandle=document.getElementById('an-id');然后handle是单节点。问题是,当我选择时它返回array而不是单个元素。所以,我的on功能失败。函数使用elm.length筛选。一切

javascript - 'this"在闭包中是如何工作的?

我到了thisdocument这表示这里发生了关闭:functionaddHandler(){document.getElementById('el').onclick=function(){this.style.backgroundColor='red';};}虽然这段代码移除了闭包:functionaddHandler(){varclickHandler=function(){this.style.backgroundColor='red';};(function(){varel=document.getElementById('el');el.onclick=clickHandl