You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jack Lukic
bba24b0092
|
11 years ago | |
---|---|---|
.. | ||
out/lib | 11 years ago | |
.npmignore | 11 years ago | |
LICENSE.md | 11 years ago | |
README.md | 11 years ago | |
package.json | 11 years ago |
README.md
Extendr
Utilities for cloning, extending, and de-referencing objects in shallow, deep, and safe ways
Install
Backend
- Install Node.js
npm install --save extendr
Frontend
Usage
Example
// Shallow Clone
(function(){
var a = {a:1}, b = {b:2}
var c = require('extendr').clone(a,b)
console.log(a) // {a:1}
console.log(b) // {b:2}
console.log(c) // {a:1,b:2}
})()
// Shallow Extend
(function(){
var a = {a:1}, b = {b:2}
var c = require('extendr').extend(a,b)
console.log(a) // {a:1,b:2}
console.log(b) // {b:2}
console.log(c) // {a:1,b:2}
})()
Methods
clone(args...)
- shallow extend the arguments into a new object, same asextend({},args...)
deepClone(args...)
- deep extend the arguments into a new object, same asdeepExtend({},args...)
dereference(obj)
- return a copy of the object with all references destroyed, same as serializing then deserializing the objectextend(args...)
- alias forshallowExtendPlainObjects
deepExtend(args...)
- alias fordeepExtendPlainObjects
shallowExtendPlainObjects(target, args...)
- shallow extend the arguments into the targetdeepExtendPlainObjects(target, args...)
- deep extend the arguments into the targetsafeShallowExtendPlainObjects(target, objs...)
- shallow extend defined values from the arguments into the targetsafeDeepExtendPlainObjects(target, args...)
- deep extend defined values from the arguments into the target
Explanation
- Use the clone methods when you don't want to modify your first object
- Use the extend methods when you want to modify the first argument
- Use the dereference method when you want to make sure that nothing has any references to the old object
- Use the safe methods when you don't want
null
andundefined
values to overwrite a defined values
History
You can discover the history inside the History.md file
License
Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton