1
0
Fork 0

Supplying alternative to getMethodInstance() for static methods

closure/master
Mike Gerwitz 2011-05-30 23:03:08 -04:00
parent 85c4c70b7d
commit 9db4e8d99f
2 changed files with 17 additions and 8 deletions

View File

@ -242,7 +242,11 @@ exports.build = function extend()
prop_init,
abstract_methods,
members,
static_members
static_members,
function( inst )
{
return inst.___$$svis$$ || new_class.___$$svis$$;
}
);
// reference to the parent prototype (for more experienced users)
@ -485,7 +489,7 @@ function createAbstractCtor( cname )
function buildMembers(
props, class_id, base, prop_init, abstract_methods, members,
static_members
static_members, staticInstLookup
)
{
var hasOwn = Array.prototype.hasOwnProperty,
@ -552,7 +556,12 @@ function buildMembers(
method: function( name, func, is_abstract, keywords )
{
var dest = ( keywordStatic( keywords ) ) ? smethods : members;
var is_static = keywordStatic( keywords ),
dest = ( is_static ) ? smethods : members,
instLookup = ( is_static )
? staticInstLookup
: getMethodInstance
;
// constructor check
if ( public_methods[ name ] === true )
@ -566,7 +575,7 @@ function buildMembers(
}
member_builder.buildMethod(
dest, null, name, func, keywords, getMethodInstance,
dest, null, name, func, keywords, instLookup,
class_id, base
);
@ -982,9 +991,7 @@ function getMethodInstance( inst, cid )
return ( iid && data )
? data[ cid ]
: ( inst.___$$svis$$ )
? inst.___$$svis$$
: null
: null
;
}

View File

@ -237,7 +237,9 @@ var common = require( './common' ),
// call the static method
Foo.foo();
assert.notEqual( result, Foo,
// note that the objects themselves aren't the same, due to the property
// object
assert.equal( result.foo, Foo.foo,
"Static members are bound to class definition rather than instance"
);
} )();