Javascript核心筆記:namespace

less than 1 minute read

靜態命名空間

  1. 直接指定 ```js 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 ```

  1. 使用物件實字(Object Literal Notation)

  2. 使用設計模式Module Pattern來建構

動態命名空間

未完…

Leave a Comment