var f = function(v) {
return v;
};
var f = () => 5;
// 等同于
function () { return 5 };
var sum = (num1,num2) => num1 + num2;
var sum = (num1,num2) {
return num1 + num2;
};
var getTempItem = id => ({ id: id,name: "Temp" });
const full = ({ first,last }) => first + ' ' + last;
full(person) {
return person.first + ' ' + person.last;
}
foo() {
setTimeout(() => {
console.log('args:',arguments);
},100);
}
foo(2,4,6,8)
args: [2,8]
(() {
[
(() => this.x).bind({ x: 'inner' })()
];
}).call({ x: 'outer' });
['outer']
foo::bar;
bar.bind(foo);
foo::bar(...arguments);
bar.apply(foo,arguments);
const hasOwnProperty = Object.prototype.hasOwnProperty;
hasOwn(obj,key) {
obj::hasOwnProperty(key);
}
var method = obj::obj.foo;
::obj.foo;
let log = ::console.log;
var log = console.log.bind(console);
restricted() {
"use strict";
restricted.caller; 报错
restricted.arguments; 报错
}
restricted();
> typeof () => {}
//'function'
> () => {} instanceof Function
//true
> typeof function () {}
//'function'
> function () {} instanceof Function
//true