什么是 var name = (param) => {} 在 JS 中
What is var name = (param) => {} in JS
我正在使用 React-Router 测试存根示例,我以前从未见过这种 class 约定。我猜这是 ES6 特有的?
var stubRouterContext = (Component, props, stubs) => {
function RouterStub() { }
Object.assign(RouterStub, {
makePath () {},
makeHref () {},
transitionTo () {},
replaceWith () {},
goBack () {},
getCurrentPath () {},
getCurrentRoutes () {},
getCurrentPathname () {},
getCurrentParams () {},
getCurrentQuery () {},
isActive () {},
getRouteAtDepth() {},
setRouteComponentAtDepth() {}
}, stubs);
return React.createClass({
childContextTypes: {
router: React.PropTypes.func,
routeDepth: React.PropTypes.number
},
getChildContext () {
return {
router: RouterStub,
routeDepth: 0
};
},
render () {
return <Component {...props} />
}
});
};
为什么我在执行此操作时会收到 TypeError: object is not function?
var Subject = stubRouterContext(Handler, props);
这是 link 文档 https://github.com/rackt/react-router/blob/master/docs/guides/testing.md
它是 ES6 特定的,它是箭头 shorthand:https://github.com/lukehoban/es6features#arrows
"Arrows are a function shorthand using the =>
syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript."
我正在使用 React-Router 测试存根示例,我以前从未见过这种 class 约定。我猜这是 ES6 特有的?
var stubRouterContext = (Component, props, stubs) => {
function RouterStub() { }
Object.assign(RouterStub, {
makePath () {},
makeHref () {},
transitionTo () {},
replaceWith () {},
goBack () {},
getCurrentPath () {},
getCurrentRoutes () {},
getCurrentPathname () {},
getCurrentParams () {},
getCurrentQuery () {},
isActive () {},
getRouteAtDepth() {},
setRouteComponentAtDepth() {}
}, stubs);
return React.createClass({
childContextTypes: {
router: React.PropTypes.func,
routeDepth: React.PropTypes.number
},
getChildContext () {
return {
router: RouterStub,
routeDepth: 0
};
},
render () {
return <Component {...props} />
}
});
};
为什么我在执行此操作时会收到 TypeError: object is not function?
var Subject = stubRouterContext(Handler, props);
这是 link 文档 https://github.com/rackt/react-router/blob/master/docs/guides/testing.md
它是 ES6 特定的,它是箭头 shorthand:https://github.com/lukehoban/es6features#arrows
"Arrows are a function shorthand using the =>
syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript."