Author - StudySection Post Views - 527 views
Prototype Pattern

Javascript / Jquery – Prototype Pattern

What is a Prototype Pattern?

The prototype pattern creates objects by cloning an existing object, rather than creating non-initialized objects. It returns objects that are initialized with values that it copied from an object. This is also referred to as the “properties” pattern.
flow-chart

Prototype patterns are based on prototypal inheritance, in which we create objects that act as prototypes for other objects. Each object that the constructor builds is based on the prototype object. If the prototype of the constructor contains a property called “name,” for example, then each object created by that same constructor will also have this same property.

Examples of the prototype pattern in Javascript / Jquery

Example 1:
function person(data) {
this.data = data;
this.name = $(data).find('name');
this.designation = $(data).find('designation');
this.experience = $(data).find('experience');
};
person.prototype.init = function() {
$(this.elem).append($('<option value=""> ----- Select a Name ----- </option>'));
var t = this;
$(this.name).each(function() {
$(t.elem).append($('<option value="' + $(this).attr('name') + '">' +$(this).attr('name')+'('+ $(this).attr('designation')+ ')</option>'));
});
$(this.elem).combobox(); // from jQuery UI combobox extension
};

Example 2:
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.nationality = "English";
}
const myFather = new Person("John", "Mehta", 50, "blue");
const myMother = new Person("Sally", "Kaur", 48, "green");
document.getElementById("details").innerHTML =
"My father’s nationality is " + myFather.nationality + " and the nationality of my mother is " + myMother.nationality;

People having good knowledge of Financial accounting can get an Accounting Certification Exam from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri