这是一些宝石:
文字:
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中还可以使用其他什么语法糖?