Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Mar 31, 2015, 11:53 AM EDT
All JavaScript objects inherit the properties and methods from their prototype.
Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype.
Objects created with new Date() inherit the Date.prototype.
The Object.prototype is on the top of the prototype chain.
All JavaScript objects (Date, Array, RegExp, Function, ....) inherit from the Object.prototype.
one simple Example about the javascript Prototype.
function person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
var myFather = new person("John", "Doe", 50, "blue");
var myMother = new person("Sally", "Rally", 48, "green");
document.getElementById("demo").innerHTML =
"My father is " + myFather.age + ". My mother is " + myMother.age;
output: My Father is 50. My mother is 48.
Referenced by :
www.w3schools.com/js/js_object_prototypes.asp
Manoj BhoirRank #599 · 4K reputationPosted Apr 15, 2015, 9:14 PM EDT
The prototype property allows you to add properties and methods to an object.
Syntax
object.prototype.name=value
Example
In this example we will show how to use the prototype property to add a property to an object:
The output of the code above will be:
20000
Reference : http://www.w3schools.com/jsref/jsref_prototype_math.asp
For more details see : http://www.w3schools.com/js/js_object_prototypes.asp
http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 15, 2015, 10:42 PM EDT
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 15, 2015, 10:48 PM EDT