// the Employee object function Employee( name, email, role ) { this.name = name; this.email = email; this.role = role; } Employee.prototype.helloEmployee = function() { console.log( "Oye" + role); } // the emp object inherits from Employee function emp( name, email ) { Employee.call(this, name, email, "admin"); } emp.prototype = Object.create( Employee.prototype ); var kumar = new emp( "Kumar", "info@helloitskumar.com" ); kumar.helloEmployee();
I have tried to retrieve employee info
from javascript object but error while checking javascript console. Can you help what's wrong with my code?
Your forgot to add this
reference in console.log . check this working jsfiddle
// the Employee object function Employee( name, email, role ) { this.name = name; this.email = email; this.role = role; } Employee.prototype.helloEmployee = function() { console.log( "Oye" + this.role); } // the emp object inherits from Employee function emp( name, email ) { Employee.call(this, name, email, "admin"); } emp.prototype = Object.create( Employee.prototype ); var kumar = new emp( "Kumar", "info@helloitskumar.com" ); kumar.helloEmployee();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.