2011-03-25 00:08:23 -04:00
|
|
|
/**
|
|
|
|
* Basic class declaration example
|
|
|
|
*/
|
|
|
|
|
2011-11-05 13:04:55 -04:00
|
|
|
// Define class Dog
|
2011-03-25 00:08:23 -04:00
|
|
|
var Dog = Class( 'Dog',
|
|
|
|
{
|
2011-11-05 13:04:55 -04:00
|
|
|
'private _name': '',
|
|
|
|
|
|
|
|
|
|
|
|
__construct: function( name )
|
|
|
|
{
|
|
|
|
this._name = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2011-03-25 00:08:23 -04:00
|
|
|
'public bark': function()
|
|
|
|
{
|
2011-11-05 13:04:55 -04:00
|
|
|
console.log( this._name + ' says: Woof!' );
|
2011-03-25 00:08:23 -04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2011-11-05 13:04:55 -04:00
|
|
|
// 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();
|
2011-03-25 00:08:23 -04:00
|
|
|
|