这是来自 Material UI githubs mui line 13 的一些代码
bable2016 编译后这段代码是这样的:
(0, _extends2.default)({}, theme.typography.button, ...)
这是什么语法?任何人似乎?
编译后的整个部分。编译成功,但我仍然感到困惑 var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
root: (0, _extends2.default)({}, theme.typography.button, {
boxSizing: 'border-box',
minWidth: 64,
minHeight: 36,
padding: '8px 16px',
borderRadius: theme.shape.borderRadius,
color: theme.palette.text.primary,
transition: theme.transitions.create(['background-color', 'box-shadow', 'border'], {
duration: theme.transitions.duration.short
}),
下面第一部分的语法
(0, _extends2.default)({}, theme.typography.button, ...)
正在使用逗号运算符。
这里解释了使用的原因:Why does babel rewrite import function call to (0, fn)(...)?.
除了this
在这种情况下无关紧要的微妙之处外,它基本上等同于以下内容:
_extends2.default({}, theme.typography.button, ...);
该extends
函数的使用取代了对象扩展语法的使用,以将所有内容都包含theme.typography.button
在 Button 的“根”样式规则中。extends
与Object.assign非常相似。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句