parent
a1c1ddff74
commit
517b2be464
48
lib/class.js
48
lib/class.js
|
@ -34,6 +34,23 @@ var util = require( './util' ),
|
||||||
*/
|
*/
|
||||||
var class_meta = {};
|
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
|
* 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;
|
delete props.__name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IE has problems with toString()
|
||||||
|
if ( enum_bug )
|
||||||
|
{
|
||||||
|
if ( props.toString !== Object.prototype.toString )
|
||||||
|
{
|
||||||
|
props.__toString = props.toString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
util.propParse( props, {
|
util.propParse( props, {
|
||||||
each: function( name, value, keywords )
|
each: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
|
@ -567,15 +593,19 @@ var extend = ( function( extending )
|
||||||
members[ 'public' ], 'toString'
|
members[ 'public' ], 'toString'
|
||||||
) ) )
|
) ) )
|
||||||
{
|
{
|
||||||
this.toString = ( cname )
|
// use __toString if available (see enum_bug), otherwise use
|
||||||
? function()
|
// our own defaults
|
||||||
{
|
this.toString = members[ 'public' ].__toString
|
||||||
return '[object #<' + cname + '>]';
|
|| ( ( cname )
|
||||||
}
|
? function()
|
||||||
: function()
|
{
|
||||||
{
|
return '[object #<' + cname + '>]';
|
||||||
return '[object #<anonymous>]';
|
}
|
||||||
}
|
: function()
|
||||||
|
{
|
||||||
|
return '[object #<anonymous>]';
|
||||||
|
}
|
||||||
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -292,12 +292,13 @@ for ( var i = 0; i < class_count; i++ )
|
||||||
result = ''
|
result = ''
|
||||||
;
|
;
|
||||||
|
|
||||||
result = Class( 'Foo',
|
result = Class( 'FooToStr',
|
||||||
{
|
{
|
||||||
toString: function()
|
toString: function()
|
||||||
{
|
{
|
||||||
return str;
|
return str;
|
||||||
}
|
},
|
||||||
|
bla: function() {},
|
||||||
})().toString();
|
})().toString();
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
Loading…
Reference in New Issue