这里有一些宝石:
字面量:
var obj = {}; // Object literal, equivalent to var obj = new Object();
var arr = []; // Array literal, equivalent to var arr = new Array();
var regex = /something/; // Regular expression literal, equivalent to var regex = new RegExp('something');
默认值:
arg = arg || 'default'; // if arg evaluates to false, use 'default', which is the same as:
arg = !!arg ? arg : 'default';
我们当然知道匿名函数,但是能够将它们视为文字并在现场(作为闭包)执行它们很棒:
(function() { ... })(); // Creates an anonymous function and executes it
问题: javascript 中还有哪些出色的语法糖?