Added to class example
parent
5657e40f92
commit
f2b7ecb4a6
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue