how does it mean that return {} is an object, and then a comma separates two? Don"t understand the meaning of the book
how does it mean that return {} is an object, and then a comma separates two? Don"t understand the meaning of the book
. It's the object extender
. The second way to write it should be more intuitive
return Object.assign({}, state, { counterCaption: PPstate.counterCaption })
this code has nothing to do with react redux, but actually belongs to ES6? 7? 8. I generated the code in the babel project according to your code
, which you can refer to
let status = {
counterCaption: 1,
id :1
}
function aa() {
return {...status, [counterCaption]: status[counterCaption]PP}
}
"use strict";
var _extends = Object.assign ||
function (target) {
for (var i = 1; i < arguments.length; iPP) {
var source = arguments[i]; for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var status = {
counterCaption: 1,
id: 1
};
function aa() {
return _extends({},
status,
_defineProperty({}, counterCaption, status[counterCaption]PP));
}
when you switch to es5, you can see that the parameter counterCaption is defined into an empty object by the _ defineProperty function, and status is also an object.
is eventually extended to a new object by the _ extends function.
you need to refer to Ruan Yifeng's ES6 extension operator and deconstruction assignment
this is actually a problem with es6 grammar or it is recommended upstairs that you take a good look at teacher Ruan Yifeng's introduction to es6 http://es6.ruanyifeng.com/
and explain these two grammars
at the same time. It means
for example,
var a = {a _ var _ a = {a _ if we want to pass attributes in a to another variable, then our traditional way of writing is
var b = {apura.a _ db _ l.b}
. If we use a structure assignment, var b = {.a} directly ok
obj [content] is to find the object property
through the variable, because if you use the. + variable name directly, he must find the attribute of the variable name directly
if you use parentheses to find the worthwhile attribute corresponding to this variable
for example,
var c = {d1br 2}
var e ='d'
c.e / 2
c [e] / / 1
Previous: ReactDOM calls unmountComponentAtNode to report an error
Next: Is it necessary for front-end engineers to learn typescript now?