4.0.11 β€’ Published 7 years ago

freeze-class v4.0.11

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

#freeze-class npm version Build Status

freezer.jpg

##About: Freeze a class and its prototype.

###Note: this module is deprecated, please use the object-based module subzero

##install:

npm install freeze-class

##usage:

'use strict';

const freezeClass = require( 'freeze-class' );

class C {

	static f() { return 69; }

	f() { return 22; }
}

freezeClass( C );

/*
	the following statements will now return true:
*/

// Object.isFrozen( C );
// Object.isFrozen( C.prototype );

/*
	and the following statements will now throw TypeErrors in strict mode:
*/

// C.g = function() { return 42 };
// C.f = function() { return 42 };
// delete C.f;
// C.constant = 42;
// C.prototype.g = function() { return 42 };
// C.prototype.f = function() { return 42 };
// delete C.prototype.f;
// C.prototype.constant = 42;

##optional usage: letitgo.gif

Deep freeze a class in 'deep' mode. This will not freeze any classes within the class. It works by recursively freezing anything of type "object".

'use strict';

const freezeClass = require( 'freeze-class' );

class C {}

class InnerClass {}

InnerClass.x = {

    y: {}
};

C.a = {

    b: {

        c: {

            d: {

                InnerClass
            }
        }
    }
};

C.prototype.x = {

    y: {

        z: {}
    },

    w: {}
};

freezeClass( C, 'deep' );

/*
	the following statements will now return true:
*/

// Object.isFrozen( C );
// Object.isFrozen( C.a );
// Object.isFrozen( C.a.b );
// Object.isFrozen( C.a.b.c );
// Object.isFrozen( C.a.b.c.d );
// Object.isFrozen( C.prototype );
// Object.isFrozen( C.prototype.x );
// Object.isFrozen( C.prototype.x.y );
// Object.isFrozen( C.prototype.x.y.z );
// Object.isFrozen( C.prototype.x.w );
// !Object.isFrozen( InnerClass );
// !Object.isFrozen( InnerClass.x );
// !Object.isFrozen( InnerClass.x.y );

β„οΈπŸŽ…πŸΏπŸŽ…πŸ½πŸŽ…πŸΎπŸŽ…πŸΌβ›„οΈπŸŽΏπŸ—»πŸ‚

Deep freeze an object in 'deep' mode. This will not freeze any classes within the object. It works by recursively freezing anything of type "object".

'use strict';

const freezeClass = require( 'freeze-class' );

const o = {};

class InnerClass {}

InnerClass.x = {

    y: {}
};

o.a = {

    b: {

        c: {

            d: {

                InnerClass
            }
        }
    }
};

o.x = {

    y: {

        z: {}
    },

    w: {}
};

freezeClass( o, 'deep' );

/*
	the following statements will now return true:
*/

// Object.isFrozen( o );
// Object.isFrozen( o.a );
// Object.isFrozen( o.a.b );
// Object.isFrozen( o.a.b.c );
// Object.isFrozen( o.a.b.c.d );
// Object.isFrozen( o.x );
// Object.isFrozen( o.x.y );
// Object.isFrozen( o.x.y.z );
// Object.isFrozen( o.x.w );
// !Object.isFrozen( InnerClass );
// !Object.isFrozen( InnerClass.x );
// !Object.isFrozen( InnerClass.x.y );
4.0.11

7 years ago

4.0.10

7 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

3.0.1

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago