2012-01-09 22:41:57 -05: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
|
2011-12-26 23:23:51 -05:00
|
|
|
var inst = new Dog( 'Bob' );
|
2011-11-05 13:04:55 -04:00
|
|
|
inst.bark();
|