Javascript Class constructor pass in parameter

Description

Javascript Class constructor pass in parameter

class Monster {/*  w  ww.  ja v  a2s.  c o m*/
    constructor( options ) {
        this.health = 100;
        this.name   = options.name;
    }
}

const monster = new Monster( { name : 'fire man' } );

console.log( monster );



PreviousNext

Related