Beginning to move Class over to use member builders
parent
2a54662716
commit
eba32ed4cb
43
lib/class.js
43
lib/class.js
|
@ -214,7 +214,9 @@ var extend = ( function( extending )
|
||||||
prototype = new base();
|
prototype = new base();
|
||||||
|
|
||||||
var properties = {},
|
var properties = {},
|
||||||
members = member_builder.initMembers( prototype ),
|
members = member_builder.initMembers(
|
||||||
|
prototype, prototype, prototype
|
||||||
|
),
|
||||||
abstract_methods = ( base.abstractMethods || [] ).slice();
|
abstract_methods = ( base.abstractMethods || [] ).slice();
|
||||||
|
|
||||||
// it's much faster to lookup a hash than it is to iterate through an
|
// it's much faster to lookup a hash than it is to iterate through an
|
||||||
|
@ -226,35 +228,52 @@ var extend = ( function( extending )
|
||||||
abstract_map[ method ] = i;
|
abstract_map[ method ] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
util.propCopy( props, prototype, {
|
util.propParse( props, {
|
||||||
each: function( name, value )
|
each: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
// disallow use of our internal __initProps() method
|
// disallow use of our internal __initProps() method
|
||||||
if ( name === '__initProps' )
|
if ( name === '__initProps' )
|
||||||
{
|
{
|
||||||
throw new Error( "__initProps is a reserved method" );
|
throw new Error( "__initProps is a reserved method" );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.performDefault( name, value );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
property: function( name, value )
|
property: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
properties[ name ] = value;
|
properties[ name ] = value;
|
||||||
this.performDefault( name, value );
|
|
||||||
|
member_builder.buildProp(
|
||||||
|
members, null, name, value, keywords
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
method: function( name, func, is_abstract )
|
getter: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
var pre = prototype[ name ];
|
member_builder.buildGetter(
|
||||||
|
members, null, name, value, keywords
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
this.performDefault( name, func, is_abstract );
|
setter: function( name, value, keywords )
|
||||||
|
{
|
||||||
|
member_builder.buildSetter(
|
||||||
|
members, null, name, value, keywords
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
if ( ( pre === undefined ) && is_abstract )
|
method: function( name, func, is_abstract, keywords )
|
||||||
|
{
|
||||||
|
member_builder.buildMethod(
|
||||||
|
members, null, name, func, keywords
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( is_abstract )
|
||||||
{
|
{
|
||||||
abstract_methods.push( name );
|
abstract_methods.push( name );
|
||||||
}
|
}
|
||||||
else if ( pre && ( is_abstract === false ) )
|
else if ( ( abstract_map[ name ] !== undefined )
|
||||||
|
&& ( is_abstract === false )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// if this was a concrete method, then it should no longer
|
// if this was a concrete method, then it should no longer
|
||||||
// be marked as abstract
|
// be marked as abstract
|
||||||
|
|
|
@ -75,7 +75,9 @@ exports.buildMethod = function( members, meta, name, value, keywords )
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure parameter list is at least the length of its supertype
|
// ensure parameter list is at least the length of its supertype
|
||||||
if ( prev && ( value.length < ( prev.__length || prev.length ) ) )
|
if ( prev && (
|
||||||
|
( value.__length || value.length ) < ( prev.__length || prev.length )
|
||||||
|
) )
|
||||||
{
|
{
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
"Declaration of method '" + name + "' must be compatiable " +
|
"Declaration of method '" + name + "' must be compatiable " +
|
||||||
|
|
|
@ -381,6 +381,7 @@ exports.createAbstractMethod = function()
|
||||||
|
|
||||||
exports.defineSecureProp( method, 'abstractFlag', true );
|
exports.defineSecureProp( method, 'abstractFlag', true );
|
||||||
exports.defineSecureProp( method, 'definition', definition );
|
exports.defineSecureProp( method, 'definition', definition );
|
||||||
|
exports.defineSecureProp( method, '__length', arguments.length );
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue