定义函数
我们先来看一个基本的新特性,在javascript中,定义函数需要关键字function,但是在es6中,还有更先进的写法,我们来看:
es6写法:
var human = {
breathe(name) { //不需要function也能定义breathe函数。
console.log(name + ' is breathing...');
}
};
human.breathe('jarson'); //输出 ‘jarson is breathing...’
转成js代码:
var human = {
breathe: function(name) {
console.log(name + 'is breathing...');
}
};
human.breathe('jarson');