Fixed static bug and removed late static binding
- Late static binding will be revisited in the futureclosure/master
parent
9db4e8d99f
commit
557dcf6904
|
@ -245,7 +245,7 @@ exports.build = function extend()
|
||||||
static_members,
|
static_members,
|
||||||
function( inst )
|
function( inst )
|
||||||
{
|
{
|
||||||
return inst.___$$svis$$ || new_class.___$$svis$$;
|
return new_class.___$$svis$$;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -940,11 +940,10 @@ var common = require( './common' ),
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We support the concept of late static binding. That is, static members can be
|
* Static members cannot be overridden. Instead, static members can be *hidden*
|
||||||
* overridden by subtypes in the same way that non-static members can. This
|
* if a member of the same name is defined by a subtype.
|
||||||
* can be compared to Java, which only supports static *hiding*, not overriding.
|
|
||||||
*/
|
*/
|
||||||
( function testCanOverrideStaticMembers()
|
( function testCannotOverrideStaticMembers()
|
||||||
{
|
{
|
||||||
var val_orig = 'foobaz',
|
var val_orig = 'foobaz',
|
||||||
val = 'foobar',
|
val = 'foobar',
|
||||||
|
@ -965,7 +964,6 @@ var common = require( './common' ),
|
||||||
|
|
||||||
'public static baz': function()
|
'public static baz': function()
|
||||||
{
|
{
|
||||||
// should return overridden val
|
|
||||||
return this.$( 'prop' );
|
return this.$( 'prop' );
|
||||||
},
|
},
|
||||||
} ),
|
} ),
|
||||||
|
@ -980,24 +978,66 @@ var common = require( './common' ),
|
||||||
{
|
{
|
||||||
return val;
|
return val;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'public static getProp': function()
|
||||||
|
{
|
||||||
|
return this.$( 'prop' );
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// cannot override
|
||||||
|
assert.notEqual( SubFoo.foo(), val,
|
||||||
|
"System does not support overriding static methods"
|
||||||
|
);
|
||||||
|
assert.notEqual( SubFoo.baz(), val,
|
||||||
|
"System does not support overriding static properties"
|
||||||
|
);
|
||||||
|
|
||||||
|
// but we can hide them
|
||||||
assert.equal( SubFoo.bar(), val,
|
assert.equal( SubFoo.bar(), val,
|
||||||
"System supports overriding static methods"
|
"System supports static method hiding"
|
||||||
);
|
);
|
||||||
|
assert.equal( SubFoo.getProp(), val,
|
||||||
assert.equal( SubFoo.baz(), val,
|
"System supports static property hiding"
|
||||||
"System supports overriding static properties"
|
);
|
||||||
);
|
} )();
|
||||||
|
|
||||||
// ensure we didn't negatively impact the parent (crazy things can happen
|
|
||||||
// when you screw up an implementation)
|
/**
|
||||||
assert.equal( Foo.bar(), val_orig,
|
* Since members are statically bound, calls to parent methods should retain
|
||||||
"Subtypes' method overrides do not impact parent"
|
* access to their private members.
|
||||||
);
|
*/
|
||||||
assert.equal( Foo.baz(), val_orig,
|
( function testCallsToParentStaticMethodsRetainPrivateMemberAccess()
|
||||||
"Subtypes' property overrides do not impact parent"
|
{
|
||||||
|
var val = 'foobar',
|
||||||
|
Foo = builder.build(
|
||||||
|
{
|
||||||
|
'private static _priv': val,
|
||||||
|
|
||||||
|
'public static getPriv': function()
|
||||||
|
{
|
||||||
|
return this.$('_priv');
|
||||||
|
},
|
||||||
|
} ),
|
||||||
|
|
||||||
|
SubFoo = builder.build( Foo,
|
||||||
|
{
|
||||||
|
'public static getPriv2': function()
|
||||||
|
{
|
||||||
|
return this.getPriv();
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
;
|
||||||
|
|
||||||
|
assert.equal( SubFoo.getPriv(), val,
|
||||||
|
'Calls to parent static methods should retain access to their own ' +
|
||||||
|
'private members when called externally'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal( SubFoo.getPriv2(), val,
|
||||||
|
'Calls to parent static methods should retain access to their own ' +
|
||||||
|
'private members when called internally'
|
||||||
);
|
);
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue