An open API service indexing awesome lists of open source software.

https://github.com/serapath/deepfreeze

recursively Object.freeze() on objects and functions with properties
https://github.com/serapath/deepfreeze

Last synced: about 1 year ago
JSON representation

recursively Object.freeze() on objects and functions with properties

Awesome Lists containing this project

README

          

# deepfreeze
recursively Object.freeze() on objects and functions with properties

# usage
```js
var deepfreeze = require('deepfreeze')

/*******************************************************/
Person.prototype.say=function(){console.log('hi')}
Person.prototype.bye=function(){console.log('bye')}
function Person (name) {
return { __proto__: Person.prototype, name: name }
}
Barterer.prototype.__proto__ = Person.prototype
Barterer.prototype.clear=function(){this.inventory=[]}
function Barterer (name, inventory) {
var o = Person(name)
o.__proto__ = Barterer.prototype
o.inventory = inventory
return o
}
/*******************************************************/
var tom = new Barterer('tom', [{sugar:1},{salt:2}])

deepfreeze(tom)

tom.name = 'bill'
console.log(tom.name) // => 'tom'
tom.inventory = ['m3h']
console.log(tom.inventory) // [{sugar:1},{salt:2}]
tom.inventory.push({x:3}) // throws

deepfreeze(tom.__proto__)

tom.__proto__.clear=function (){ return 7}
tom.clear() // => 'clear'
tom.__proto__.say=function (){ return 6 }
tom.say() // => 'say'
tom.__proto__.bye=function (){ return 5 }
tom.bye() // => 'bye'

```