Сообщения

Сообщения за 2013

Universal singleton/namespace pattern for js (node.js or browser)

// File: first.js // first declaration of singletonName (e.g. for abstract interfaces) ( function ( singletonName ) { singletonName . publicProperty = 'public property value of first declaration' ; var privateProperty = 'privat property value of first declaration' ; singletonName . publicMethod = function ( ) { console . log ( 'publicMethod of first declaration to be owerwritten' ) ; } ; singletonName . toBeOverridden = function ( ) { console . log ( 'publicMethod of first declaration to be overridden ' ) ; } ; privateMethod = function ( ) { console . log ( 'privateMethod of first declaration' ) ; } ; } ( global . singletonName = global . singletonName || { } ) ) ; // File: second.js // second declaration of singletonName can extend, override and call inherited finctionality ( function ( singletonName ) { singletonName . publicProperty = 'public property value of second declaration will overwr