mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Improve IE Function#name fix and move it to straps.js, since constructor.name is used there too.
Cache result and improve RegExp.
This commit is contained in:
parent
6fe60cff9d
commit
294bfc9c9a
2 changed files with 13 additions and 9 deletions
|
@ -83,6 +83,19 @@ var Base = new function() {
|
|||
return _define(obj, name, desc);
|
||||
};
|
||||
|
||||
// Fix Function#name on browsers that do not support it (IE):
|
||||
if (!(function f() {}).name) {
|
||||
define(Function.prototype, 'name', {
|
||||
get: function() {
|
||||
var name = this.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
|
||||
// For better performance only parse once, and then cache the
|
||||
// result through a new accessor for repeated access.
|
||||
define(this, 'name', { value: name });
|
||||
return name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function that injects functions from src into dest, overriding
|
||||
* (and inherinting from) base.
|
||||
|
|
|
@ -10,15 +10,6 @@
|
|||
* All rights reserved.
|
||||
*/
|
||||
|
||||
// First see if Function#name works, and emulate it through an accessor if not.
|
||||
if (!(function f() {}).name) {
|
||||
Base.define(Function.prototype, 'name', {
|
||||
get: function() {
|
||||
return this.toString().match(/^function\s*(\w*)\s*\(/)[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Base
|
||||
* @class
|
||||
|
|
Loading…
Reference in a new issue