diff --git a/lib/class_builder.js b/lib/class_builder.js index af703d2..41f7a85 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -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 ; } diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index cf3afc3..b5cce5b 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -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" ); } )();