-
object literal
var myObject = { name: "Jack B. Nimble", 'goto': 'Jail', grade: 'A', level: 3, "3": "three" }; alert(myObject.name); alert(myObject["name"]); alert(myObject["goto"]); alert(myObject.goto); //ok alert(myObject["3"]); //alert(myObject.3); //error
-
function overload
function.length can tell you the number of parameters defined, using this we can create overload functions
-
later method
Object.prototype.later = function (msec, method) { var context = this, args = Array.prototype.slice.apply(arguments, [2]); if (typeof method === 'string') { method = context[method]; } setTimeout(function () { method.apply(context, args); }, msec); return context; };
-
fixed a closure bug
Closure refer the ability that a function can access and manipulate external variable from with a function. Sometimes, this is not good because the if a function depends on the external state. When the external state changes, the function may produce unexpected result.
-
efficency string operation
Because string is immutable in JavaScript, concatenation with array.join('') is much efficient. The following code use all the chinese characters. Click here to show