Bha*_*gav 2 javascript function vue.js
在Vue组件的方法中,我读了这个代码,其中函数以这种方式定义
methods : {
onEditorChange({ editor, html, text }) {
console.log('editor change!', editor, html, text)
this.content = html
}
}
Run Code Online (Sandbox Code Playgroud)
我检查了代码,它正在工作.我们可以向这样的函数声明形式参数吗?您可以在https://github.com/surmon-china/vue-quill-editor中找到代码段.
这被称为Destructuring.
来自:http: //2ality.com/2015/01/es6-destructuring.html#parameter-handling
在ECMAScript 5中,您将实现selectEntries(),如下所示:
function selectEntries(options) {
options = options || {};
var start = options.start || 0;
var end = options.end || getDbLength();
var step = options.step || 1;
···
}
Run Code Online (Sandbox Code Playgroud)
在ECMAScript 6中,您可以使用destructuring,如下所示:
function selectEntries({ start=0, end=-1, step=1 }) {
···
};
Run Code Online (Sandbox Code Playgroud)