使用ES6类糖,我们可以这样定义函数:
class Foo {
constructor(props) {}
...
myFn() {}
}
在 JS 对象字面量中,我们可以定义getters and setters像这样:
foo = {
get data() {}
set data(val) {}
}
但是,这个语法是什么:
foo = {
data() {}
}
这个对象是数据属性吗?或者吸气剂/吸气剂?
note: this syntax is extensively used in Vue.js 2.0 doc, like the new added render
function.
new Vue({
render (h) {
throw new Error('oops')
},
renderError (h, err) {
return h('pre', { style: { color: 'red' }}, err.stack)
}
}).$mount('#app')
它只是简写。参考MDN文档
// Shorthand method names (ES2015)
var o = {
// doesnt need a colon!
property([parameters]) {},
get property() {},
set property(value) {}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)