mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-23 15:59:45 -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.
|
// Extend Base with utility functions used across the library.
|
||||||
Base.inject({
|
Base.inject({
|
||||||
statics: true,
|
|
||||||
|
|
||||||
|
clone: function() {
|
||||||
|
return new this.constructor(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
statics: {
|
||||||
read: function(list, start, length) {
|
read: function(list, start, length) {
|
||||||
var start = start || 0,
|
var start = start || 0,
|
||||||
length = length || list.length - start;
|
length = length || list.length - start;
|
||||||
|
@ -97,8 +101,8 @@ Base.inject({
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function for rendering numbers to strings at a precision of up
|
* Utility function for rendering numbers to strings at a precision of
|
||||||
* to 5 fractional digits.
|
* up to 5 fractional digits.
|
||||||
*/
|
*/
|
||||||
formatNumber: function(num) {
|
formatNumber: function(num) {
|
||||||
return (Math.round(num * 100000) / 100000).toString();
|
return (Math.round(num * 100000) / 100000).toString();
|
||||||
|
@ -113,4 +117,5 @@ Base.inject({
|
||||||
this.push(key + ': ' + value);
|
this.push(key + ': ' + value);
|
||||||
}, []).join(', ') + ' }';
|
}, []).join(', ') + ' }';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue