Added extend method to Interface
parent
78e1913eb9
commit
60025bd048
|
@ -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 );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue