1
0
Fork 0

Added extend method to Interface

closure/master
Mike Gerwitz 2010-12-01 23:27:31 -05:00
parent 78e1913eb9
commit 60025bd048
2 changed files with 50 additions and 0 deletions

View File

@ -58,6 +58,7 @@ function extend()
util.propCopy( props, prototype ); util.propCopy( props, prototype );
attach_extend( new_interface );
new_interface.prototype = prototype; new_interface.prototype = prototype;
new_interface.constructor = new_interface; new_interface.constructor = new_interface;
@ -90,3 +91,29 @@ function prop_check( props )
return props; return props;
} }
/**
* Attaches extend method to the given function (interface)
*
* @param {Function} func function (interface) to attach method to
*
* @return {undefined}
*/
function attach_extend( func )
{
/**
* Shorthand for extending interfaces
*
* This method can be invoked on the object, rather than having to call
* Interface.extend( this ).
*
* @param {Object} props properties to add to extended interface
*
* @return {Object} extended interface
*/
util.defineSecureProp( func, 'extend', function( props )
{
return extend( this, props );
});
}

View File

@ -91,3 +91,26 @@ assert.ok(
"Interfaces can be extended with additional abstract methods" "Interfaces can be extended with additional abstract methods"
); );
assert.ok(
( BaseType.extend instanceof Function ),
"Interface contains extend method"
);
var SubType2 = BaseType.extend(
{
second: abstractMethod(),
});
assert.ok(
( new SubType2 instanceof BaseType ),
"Interface extend method can extend interfaces"
);
assert.ok(
( SubType2.prototype.second instanceof Function ),
"Interfaces can be extended with additional abstract methods using " +
"shorthand extend method"
);