1. By Direct Assignment var myApp = {} myApp.id = 0; myApp.next = function() { return myApp.id++; } myApp.reset = function() { myApp.id = 0; } window.console && console.log( myApp.next(), myApp.next(), myApp.reset(), myApp.next() ); //0, 1, undefined, 0 var myApp = {} myApp.id = 0; myApp.next = function() { return this.id++; } myApp.reset = function() { this.id = 0; } myApp.next(); //0 myApp.nex..
* Javascript RegEx Api The RegExp object RegExp 글로벌 오브젝트는 3가지 사용을 제시한다. var a = new RegExp("\\b[\\w]{4}\\b","g"); //match all four letter words //same as... a = /\b\w{4}\b/g; a.constructor //RegExp() "(penalty)Lampard, Frank(1-0)".match(/\b([\w]+),\s?([\w]+)/g); RegExp.leftContext //"(penalty)" RegExp.rightContext //"(1-0)" RegExp.$1 //"Lampard" RegExp.$2 //"Frank" var a = /\b[a-z]{10,}\b/i; //m..
Invoke a property alert(this); //window var a = { b : function(){ return this; } }; a.b(); //a; a['b'](); //a; var c = {}; c.d = a.b; c.d() //c Invoke a variable var a = { b : function() { return this; } }; var foo = a.b; foo() // window var a = { b: function(){ var c = function() { return this; } return c(); } }; a.b(); //window var a = { b : function() { return (function() { return this;})() }..
String.prototype.split(separator, limit) "85@@86@@53".split("@@"); //['85', '86', '53']; "bannana".split(); //["banana"]; "원,투,쓰리".split(",",2); // ["원","투"] Array.prototype.join(separator) 배열을 스트링으로 변환 합니다. ["slugs","snails","puppy dog's tails"].join(' and '); //"slugs and snails and puppy dog's tails" ['Giants', 4, 'Rangers', 1].join(' '); //"Giants 4 Rangers 1" [1962,1989,2002,2010].join(); /..
//Using hasOwnProperty to build resilient object looping. Object.prototype.otherKey = "otherValue"; var object = { key: "value" }; for ( var prop in object ) { if ( object.hasOwnProperty( prop ) ) { assert( prop, "key","There should only be one iterated property." ); } } //XPath if ( typeof document.evaluate === "function" ) { function getElementsByXPath(expression, parentElement) { var results ..