我最近了解了使用ES6和箭头函数的方法,并且有一个问题,正如已经讨论过的,我无法定义。
功能正常:
var func = function(name, props) {
'use strict';
var vnode, rest = [], children = [], i;
for (i = arguments.length; i-- > 2; ) {
rest.push(arguments[i]);
}
while (rest.length > 0) {
if (Array.isArray((vnode = rest.pop()))) {
for (i = vnode.length; i-- > 0; ) {
rest.push(vnode[i]);
}
} else if (vnode === false || vnode === true || vnode === null) {
} else {
children.push(typeof vnode === "object" ? vnode : createTextNodes(vnode));
}
}
props = props || {};
return typeof name === "function"
? name(props, children)
: createNode(name, props, children, null, props.key);
};
相同的箭头功能不起作用:
const func = (name, props) => {
'use strict';
let vnode, rest = [], children = [], i;
for (i = arguments.length; i-- > 2; ) {
rest.push(arguments[i]);
}
while (rest.length > 0) {
if (Array.isArray((vnode = rest.pop()))) {
for (i = vnode.length; i-- > 0; ) {
rest.push(vnode[i]);
}
} else if (vnode === false || vnode === true || vnode === null) {
} else {
children.push(typeof vnode === "object" ? vnode : createTextNodes(vnode));
}
}
props = props || {};
return typeof name === "function"
? name(props, children)
: createNode(name, props, children, null, props.key);
};
返回以下错误:
Uncaught ReferenceError: arguments is not defined
我发现参数未传递到箭头函数中,但找不到解决方案。
解决任何想法?预先感谢