1
0
Fork 0

Began implementing constructor (not yet operable - test will fail)

closure/master
Mike Gerwitz 2010-11-10 19:02:52 -05:00
parent 8d6c2645bc
commit 1ee270883e
2 changed files with 31 additions and 3 deletions

View File

@ -50,9 +50,16 @@ var extend = function()
base = args.pop() || Class,
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;
}

View File

@ -33,7 +33,14 @@ assert.ok(
// create a basic test class
var Foo = Class.extend();
var construct_count = 0;
var Foo = Class.extend(
{
__construct: function()
{
construct_count++;
},
});
assert.ok(
@ -45,3 +52,17 @@ assert.ok(
( Foo.prototype.extend instanceof Function ),
"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"
);