1
0
Fork 0

Added to class example

website
Mike Gerwitz 2011-11-05 13:04:55 -04:00
parent 5657e40f92
commit f2b7ecb4a6
1 changed files with 17 additions and 2 deletions

View File

@ -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();