我正在使用React-Router测试存根示例,我之前从未见过这个类约定。我猜这是特定的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不是函数?
var Subject = stubRouterContext(Handler, props);
这是指向文档https://github.com/rackt/react-router/blob/master/docs/guides/testing.md
的链接答案 0 :(得分:0)
特定于ES6,它是箭头速记:https://github.com/lukehoban/es6features#arrows
&#34;箭头是使用=>
语法的函数简写。它们在语法上类似于C#,Java 8和CoffeeScript中的相关功能。&#34;