mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Add a generic clone() method to all classes through Base which creates a new item using the constructor and passing 'this'.
This commit is contained in:
parent
6854f7d026
commit
b37ba3d858
1 changed files with 97 additions and 92 deletions
|
@ -16,8 +16,12 @@
|
|||
|
||||
// Extend Base with utility functions used across the library.
|
||||
Base.inject({
|
||||
statics: true,
|
||||
|
||||
clone: function() {
|
||||
return new this.constructor(this);
|
||||
},
|
||||
|
||||
statics: {
|
||||
read: function(list, start, length) {
|
||||
var start = start || 0,
|
||||
length = length || list.length - start;
|
||||
|
@ -97,8 +101,8 @@ Base.inject({
|
|||
},
|
||||
|
||||
/**
|
||||
* Utility function for rendering numbers to strings at a precision of up
|
||||
* to 5 fractional digits.
|
||||
* Utility function for rendering numbers to strings at a precision of
|
||||
* up to 5 fractional digits.
|
||||
*/
|
||||
formatNumber: function(num) {
|
||||
return (Math.round(num * 100000) / 100000).toString();
|
||||
|
@ -113,4 +117,5 @@ Base.inject({
|
|||
this.push(key + ': ' + value);
|
||||
}, []).join(', ') + ' }';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue