草庐IT

re-assign

全部标签

javascript - react : componentDidMount + setState not re-rendering the component

我对使用componentDidMount和setState来使用react并努力更新自定义组件相当陌生,这似乎是推荐的做法。下面是一个示例(包括用于获取数据的axiosAPI调用):importReactfrom'react';import{MyComponent}from'my_component';importaxiosfrom'axios';exportdefaultclassExampleextendsReact.Component{constructor(props){super(props);this.state={data:[]};}GetData(){returnax

javascript - JavaScript 中的 Object.assign 和 Object.setPrototypeOf 有什么区别?

假设我有一个具有speak功能的动物对象:functionspeak(){console.log(this.sound)}letanimal={speak}我有一只狗,它会发出声音:letdog={sound:"Woof!"}如果我想让dog从animal继承speak我可以使用Object.assign或对象.setPrototypeOf。它们似乎产生相同的结果:letluke=Object.assign(dog,animal)luke.speak()//Woof!letbruno=Object.setPrototypeOf(dog,animal)bruno.speak()//Woo

javascript - 为什么我的计算属性在 Object.assign 之后无效?

这个问题在这里已经有了答案:Object.assigngettersandsettersinconstructor(1个回答)关闭3年前。我在现代JavaScript中偶然发现了类似这样的代码:letobj={data:{number:9},setprop(p){this.data=p;},getprop(){returnthis.data;}};obj=Object.assign({},obj,{data:{number:2}});console.log('obj.data===obj.prop',obj.data===obj.prop);console.log('obj.data.

javascript - Object.assign 构造函数中的 getter 和 setter

我尝试通过Object.assign在构造函数中定义getter和setter:functionClass(){Object.assign(this,{getprop(){console.log('callget')},setprop(v){console.log('callset')},});}varc=newClass();//(1)=>'callget'console.log(c.prop);//(2)=>undefinedc.prop='change';console.log(c.prop);//(3)=>'change'问题:(1)为什么要调用getter?(2)为什么不调用

javascript - JS函数声明: curly brace object assigned with an empty object in parameter declaration

这是代码,exportfunctioncreateConnect({connectHOC=connectAdvanced,mapStateToPropsFactories=defaultMapStateToPropsFactories,mapDispatchToPropsFactories=defaultMapDispatchToPropsFactories,mergePropsFactories=defaultMergePropsFactories,selectorFactory=defaultSelectorFactory}={}){...}函数参数声明中的{connectHOC=

javascript - 中级 JavaScript : assign a function with its parameter to a variable and execute later

我有一个JavaScript函数:functionalertMe($a){alert($a);}我可以这样执行:alertMe("Hello");我想做的是将带有"Hello"参数的alertMe("Hello")赋给一个变量$func,然后稍后可以通过执行$func();之类的操作来执行此操作。 最佳答案 我想添加评论作为答案代码//definethefunctionfunctionalertMe(a){//returnthewrappedfunctionreturnfunction(){alert(a);}}//declaret

使用 "this = "的 Javascript 函数给出 "Invalid left-hand side in assignment"

我试图让一个JavaScript对象使用另一个对象的构造函数的“this”赋值,并假定所有对象的原型(prototype)函数。这是我试图完成的示例:/*Thebase-containsassignmentsto'this',andprototypefunctions*/functionObjX(a,b){this.$a=a;this.$b=b;}ObjX.prototype.getB(){returnthis.$b;}functionObjY(a,b,c){//here'swhatI'mthinkingshouldwork:this=ObjX(a,b*12);/*andby'work

javascript - Typescript "Cannot assign to property, because it is a constant or read-only"即使属性未标记为只读

我有以下代码typeSetupProps={defaults:string;}exportclassSetupextendsReact.Component{constructor(props:any){super(props);this.props.defaults="Whatever";}尝试运行此代码时,TS编译器返回以下错误:Cannotassignto'defaults'becauseitisaconstantoraread-onlyproperty.deafualts是只读属性,但显然没有这样标记。 最佳答案 您正在扩展R

javascript - AWS认知: How to assign user to a user group when user signs up

我在awscognito中有以下用户组。行政成员付费成员(member)我想在所有用户注册我的应用程序时将所有用户默认分配到Member用户组,这样我就可以为该用户组分配不同的IAMAngular色。如何以编程方式将用户分配给用户组? 最佳答案 我发现我可以使用adminAddUserToGroup将用户添加到您在AWSCognito上设置的特定组。http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#ad

javascript - 错误 TS2539 : Cannot assign to 'c' because it is not a variable

我有2个.ts文件,C.ts:exportletc:any=10;A.ts:import{c}from"./C";c=100;编译A.ts时报错:errorTS2539:Cannotassignto'c'becauseitisnotavariable.我该如何解决? 最佳答案 将它放在一个类中,并使其成为静态的exportclassGlobalVars{publicstaticc:any=10;}从任何其他文件导入之后GlobalVars.c=100; 关于javascript-错误TS