class with javascript
prototype methodS
by Rebecca Chen
JavaScript
// Person constructor
function Person (firstName) {
this.firstName = firstName;
}
// methods of Person
Person.prototype = {
sayHello: function() {
console.log("Hello, I'm " + this.firstName);
},
sayBye: function() {
console.log("See you");
}
}
//////////////////////////////////////////////////////////
var person1 = new Person("Alice");
var person2 = new Person("Bob");
// logs "Hello, I'm Alice"
person1.sayHello();
// logs "Hello, I'm Bob"
person2.sayBye();