JavaScriptでシングルトンを保証
私はシングルトンのパターンを思い出し、「どうしてそんなことしないの?」と思いました。
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
function a ( ) { // a.constructor = Function() var property ; this . property = function ( value ) { if ( value ) { property = value ; return property ; } else { return property ; } } } a = new a ( ) ; // a.constructor = a() var b = new a ( ) ; // Error: a is not a constructor
オブジェクトには、実装を隠すなど、すべての利点がありますが、コンストラクターはありません。
PSチェックインFF(3.6、3.5、3.0、2.0)、Chrome 4、Safari 4、Opera(10.10、9.64、9.0)、およびIE(8、7、6)。