parent
a1c1ddff74
commit
517b2be464
32
lib/class.js
32
lib/class.js
|
@ -34,6 +34,23 @@ var util = require( './util' ),
|
|||
*/
|
||||
var class_meta = {};
|
||||
|
||||
/**
|
||||
* IE contains a nasty enumeration "bug" (poor implementation) that makes
|
||||
* toString unenumerable. This means that, if you do obj.toString = foo,
|
||||
* toString will NOT show up in `for` or hasOwnProperty(). This is a problem.
|
||||
*
|
||||
* This test will determine if this poor implementation exists.
|
||||
*/
|
||||
var enum_bug = (
|
||||
Object.prototype.propertyIsEnumerable.call(
|
||||
{ toString: function() {} },
|
||||
'toString'
|
||||
) === false
|
||||
)
|
||||
? true
|
||||
: false
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* This module may be invoked in order to provide a more natural looking class
|
||||
|
@ -419,6 +436,15 @@ var extend = ( function( extending )
|
|||
delete props.__name;
|
||||
}
|
||||
|
||||
// IE has problems with toString()
|
||||
if ( enum_bug )
|
||||
{
|
||||
if ( props.toString !== Object.prototype.toString )
|
||||
{
|
||||
props.__toString = props.toString;
|
||||
}
|
||||
}
|
||||
|
||||
util.propParse( props, {
|
||||
each: function( name, value, keywords )
|
||||
{
|
||||
|
@ -567,7 +593,10 @@ var extend = ( function( extending )
|
|||
members[ 'public' ], 'toString'
|
||||
) ) )
|
||||
{
|
||||
this.toString = ( cname )
|
||||
// use __toString if available (see enum_bug), otherwise use
|
||||
// our own defaults
|
||||
this.toString = members[ 'public' ].__toString
|
||||
|| ( ( cname )
|
||||
? function()
|
||||
{
|
||||
return '[object #<' + cname + '>]';
|
||||
|
@ -576,6 +605,7 @@ var extend = ( function( extending )
|
|||
{
|
||||
return '[object #<anonymous>]';
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -292,12 +292,13 @@ for ( var i = 0; i < class_count; i++ )
|
|||
result = ''
|
||||
;
|
||||
|
||||
result = Class( 'Foo',
|
||||
result = Class( 'FooToStr',
|
||||
{
|
||||
toString: function()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
},
|
||||
bla: function() {},
|
||||
})().toString();
|
||||
|
||||
assert.equal(
|
||||
|
|
Loading…
Reference in New Issue