1
0
Fork 0
easejs/scripts/ex/class.js

30 lines
462 B
JavaScript
Raw Normal View History

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