Began implementing constructor (not yet operable - test will fail)
parent
8d6c2645bc
commit
1ee270883e
|
@ -50,9 +50,16 @@ var extend = function()
|
||||||
base = args.pop() || Class,
|
base = args.pop() || Class,
|
||||||
|
|
||||||
prototype = new base(),
|
prototype = new base(),
|
||||||
new_class = function() {};
|
new_class = function()
|
||||||
|
{
|
||||||
|
if ( this.__construct instanceof Function )
|
||||||
|
{
|
||||||
|
this.__construct.apply( this, arguments );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
new_class.prototype = prototype;
|
new_class.prototype = prototype;
|
||||||
|
new_class.constructor = new_class;
|
||||||
|
|
||||||
return new_class;
|
return new_class;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,14 @@ assert.ok(
|
||||||
|
|
||||||
|
|
||||||
// create a basic test class
|
// create a basic test class
|
||||||
var Foo = Class.extend();
|
var construct_count = 0;
|
||||||
|
var Foo = Class.extend(
|
||||||
|
{
|
||||||
|
__construct: function()
|
||||||
|
{
|
||||||
|
construct_count++;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -45,3 +52,17 @@ assert.ok(
|
||||||
( Foo.prototype.extend instanceof Function ),
|
( Foo.prototype.extend instanceof Function ),
|
||||||
"Created class contains extend method in prototype"
|
"Created class contains extend method in prototype"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
construct_count,
|
||||||
|
0,
|
||||||
|
"Constructor should not be called before class is instantiated"
|
||||||
|
);
|
||||||
|
|
||||||
|
var obj = new Foo();
|
||||||
|
assert.equal(
|
||||||
|
construct_count,
|
||||||
|
1,
|
||||||
|
"Constructor should be invoked once the class is instantiated"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue