From f2b7ecb4a648463c1ae13e584a2c962f287d2701 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 5 Nov 2011 13:04:55 -0400 Subject: [PATCH] Added to class example --- scripts/ex/class.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/ex/class.js b/scripts/ex/class.js index 2ad90b7..04e0a6e 100644 --- a/scripts/ex/class.js +++ b/scripts/ex/class.js @@ -2,13 +2,28 @@ * Basic class declaration example */ +// Define class Dog var Dog = Class( 'Dog', { + 'private _name': '', + + + __construct: function( name ) + { + this._name = name; + }, + + 'public bark': function() { - console.log( 'Woof!' ); + console.log( this._name + ' says: Woof!' ); } } ); -Dog().bark(); +// invoke method 'bark' on a new instance of 'Dog' +Dog( 'Fluffy' ).bark(); + +// alternatively, we can use the 'new' keyword +var inst = new Dog( 'Rompie' ); +inst.bark();