Clonable 1.0.2
An Utility Class allowing the instances of a class implementing it to be cloned.
Details
- Author
- Kevin Chapelier
- Current version
- 1.0.2
- GitHub
- DEEO/Clonable
- Downloads
- 4291
- Category
- Utilities
- Tags
- Report
- GitHub Issues
How to use
if(console && console.log) alert = console.log;
var Example = new Class({
Implements: [Clonable],
text: 'This is the original object',
log: function()
{
alert(this.text);
},
cloneInitialize: function() // see Notes
{
this.text = 'This is a clone';
}
});
var object = new Example();
var clone = object.clone();
alert(object == clone); // false
object.log(); // 'This is the original object'
clone.log(); // 'This is a clone'
History
1.0.2 (2010-03-04)
- Better handling of the cloneInitialize method (see notes)
1.0.1 (2010-02-28)
- Bug fix release (self and cross-references handling)
1.0 (2010-02-28)
- First release
Notes
- One argument (boolean) can be passed to the method clone to indicate if all objects referenced in the cloned object should also be cloned (by default, they'll be passed by reference).
- If the class implements a method called cloneInitialize, it will be called on each clones [starting 1.0.2] once all objects have been cloned.
- [starting 1.0.2] The method 'cloneInitialize' gets two arguments : the original object and a boolean indicating if it was a deep clone (see above).
- Handles self-references and cross-references by using the property $clone.
Discuss
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus