function Person(name, title) {
this.name = name;
this.title = title;
}
Person.prototype.getName = function () {
return this.name;
};
Person.prototype.sayHelloFrom = function (who) {
var who = who || 'Nobody';
return 'Hi, ' + this.name + '! I am ' + who;
};
// -----------
var Jack = new Person('Jack', 'Doctor');
Jack.getName(); // ---> Jack
Jack.sayHelloFrom('Peter'); // ---> Hi, Jack! I am Peter
Jack.sayHelloFrom(); // ---> Hi, Jack! I am Nobody
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.