草庐IT

reference-parameters

全部标签

javascript - 对象内的 XMLHttpRequest : how to keep the reference to "this"

我从javascript对象内部进行一些Ajax调用。:myObject.prototye={ajax:function(){this.foo=1;varreq=newXMLHttpRequest();req.open('GET',url,true);req.onreadystatechange=function(aEvt){if(req.readyState==4){if(req.status==200){alert(this.foo);//referencetothisislost}}}};在onreadystatechange函数中,this不再引用主对象,所以我无权访问this

javascript - AngularJS fn is not a function error using $timeout with a function with parameters 错误

我正在制作一个您可以编辑文本的网页,在您停止输入1秒后,它会自动保存您输入的内容。目前我正在研究$timeout的细节。当我调用没有参数的update方法时,它可以正常工作,但是当我使用参数调用它时,我得到错误:Error:fnisnotafunction$TimeoutProvider/this.$get为什么我在执行以下操作时会收到此错误:timeout=$timeout(update(element,content),1000);但不是当我这样做的时候:timeout=$timeout(update,1000);显然我需要将参数传递给更新方法,因为我需要知道要更新什么。debou

javascript - 为什么 push 显示 argument of type 'any[]' is not assignable to parameter of type 'never' 错误?

在这段代码中我得到了休闲错误:Argumentoftype'any[]'isnotassignabletoparameteroftype'never'varmarkers:[];this.Getlapoints(this.map.getCenter(),500000).then(data=>{for(varkeyindata){Leaflet.marker(data[key].location,//{icon:greenIcon}).addTo(this.map).bindPopup(data[key].caption);//markers.push(data[key].locatio

javascript - Lint 警告 : parseInt missing radix parameter

这个问题在这里已经有了答案:JSLintsays"missingradixparameter"(11个答案)关闭9年前。我有以下代码给出标题中描述的警告:year:parseInt(dateParts[0]),......................^非常感谢任何帮助

javascript - 方法参数 : destructuring + keeping original parameter (ReactJS component)

这个问题在这里已经有了答案:ES6destructuringfunctionparameter-namingrootobject(5个答案)关闭3年前。有没有办法实现方法参数解构,又能获取方法参数。在具有无状态组件的React应用程序的上下文中,我希望能够替换constMyComponent=(props)=>{const{prop1,prop2}=props;return()}使用更简洁的语法,如constMyComponent=(props:{prop1,prop2})()有没有类似的语法可用?

javascript - ECMAScript(ECMA-262 5.1)中的 `base value` 的 `reference` 是什么?

我一直在尝试理解this值是如何在javascript中设置的,并且发现ECMAScript语言规范非常有用。我在读section8.7referencespecificationtype发现ECMAScript中的引用由3个部分组成,basevalue,referencedname,strictreferenceflag了解section11.2.3.我可以根据他们的名字假设什么是referencedname和strictreferenceflag,但我不明白什么是basevalue.文件说basevalue是undefined,String,Boolean,Number和Objec

javascript - Angular : Pass additional parameters to chained promises

我想链接一些由服务返回的promise。只要某些返回promise的方法不需要额外的参数,这就可以工作。这是我的例子:varfirst=function(){vard=$q.defer();$timeout(function(){d.resolve("firstresolved")},100)returnd.promise;};varsecond=function(val){console.log("valueofval:",val);vard=$q.defer();$timeout(function(){d.resolve("secondresolved")},200)returnd

戈朗 : Is there a way to modify one of the multi-value return parameters in one line?

我正在尝试在Go中做一些相对简单的事情——将字符串转换为整数,然后将其加倍:myInt,_:=strconv.Atoi(args[1])doubleArg:=myInt*2由于Atoi()返回两个参数(整数和err),我使用myInt,_:=来检索值的整数。我想将它加倍(因此是第二行)但不能在一行中完成所有操作:myInt,_:=strconv.Atoi(args[1])*2给我:multiple-valuestrconv.Atoi()insingle-valuecontext但是,根据我使用大多数其他语言的经验,必须在两行中执行此操作似乎有很多样板。这只是我必须处理的一个限制,还是有

pointers - 调用结构函数给出 "cannot refer to unexported field or method"

我有这样的结构:typeMyStructstruct{Idstring}和函数:func(m*MyStruct)id(){//doingsomethingwithidhere}我还有一个这样的结构:typeMyStruct2struct{m*MyStruct}现在我有一个函数:funcfoo(str*MyStruct2){str.m.id()}但是我在编译时遇到错误:str.m.idundefined(cannotrefertounexportedfieldormethodmypackage.(*MyStruct)."".id如何正确调用这个函数? 最佳答案

戈朗 : Passing structs as parameters of a function

尝试通过在线类(class)自学围棋。而且我正在尝试稍微偏离路线以扩展我的学习。该类(class)让我们使用几个变量编写一个简单的函数,该函数将获取这两个变量并打印出一行。所以我有:funcmain(){vargreeting:="hello"varname:="cleveland"message:=printMessage(greeting,name)fmt.Println(message)}funcprintMessage(greetingstring,namestring)(messagestring){returngreeting+""+name+"!"}稍后类(class)介