Avoid object creation and an unnecessary function call in Class#addMethods
, when working around JScript DontEnum bug.
This commit is contained in:
parent
18f2ac65c3
commit
b3fc07922c
@ -1,3 +1,5 @@
|
||||
* Avoid object creation and an unnecessary function call in `Class#addMethods`, when working around JScript DontEnum bug. Replace with feature test and a simple boolean check at runtime. (kangax)
|
||||
|
||||
* Optimize Element#immediateDescendants. (kangax, Tobie Langel)
|
||||
|
||||
* Remove unnecessary function object creation and `Number#times` in `Element._getContentFromAnonymousElement`. (kangax)
|
||||
|
@ -9,6 +9,17 @@
|
||||
* inheritance](http://prototypejs.org/learn/class-inheritance).
|
||||
**/
|
||||
var Class = (function() {
|
||||
|
||||
// Some versions of JScript fail to enumerate over properties, names of which
|
||||
// correspond to non-enumerable properties in the prototype chain
|
||||
var IS_DONTENUM_BUGGY = (function(){
|
||||
for (var p in { toString: 1 }) {
|
||||
// check actual property name, so that it works with augmented Object.prototype
|
||||
if (p === 'toString') return false;
|
||||
}
|
||||
return true;
|
||||
})();
|
||||
|
||||
/**
|
||||
* Class.create([superclass][, methods...]) -> Class
|
||||
* - superclass (Class): The optional superclass to inherit methods from.
|
||||
@ -138,9 +149,10 @@ var Class = (function() {
|
||||
var ancestor = this.superclass && this.superclass.prototype,
|
||||
properties = Object.keys(source);
|
||||
|
||||
// IE6 doesn't enumerate toString and valueOf properties,
|
||||
// Force copy if they're not coming from Object.prototype.
|
||||
if (!Object.keys({ toString: true }).length) {
|
||||
// IE6 doesn't enumerate `toString` and `valueOf` (among other built-in `Object.prototype`) properties,
|
||||
// Force copy if they're not Object.prototype ones.
|
||||
// Do not copy other Object.prototype.* for performance reasons
|
||||
if (IS_DONTENUM_BUGGY) {
|
||||
if (source.toString != Object.prototype.toString)
|
||||
properties.push("toString");
|
||||
if (source.valueOf != Object.prototype.valueOf)
|
||||
|
Loading…
Reference in New Issue
Block a user