I've decided to write more OOP articles in WinJS library regarding the use of Design Patterns we all love! You can learn more in my previous parts:
Let's start with what this design pattern means.
What is Prototype Design Pattern?
Prototype helps you create prototype instances of the objects and lets you clone them. It's widely used in Javascript especially in jQuery library.
According to DoFactory,a prototype factory has three objects:


My Prototype example has the same amount of objects as DoFactory's.
Professional Object
ProfessionalPrototype Object
Clone Object
We shall create Professionals from Prototype and then create clones.
Let's see some code!
Implementation
Let's create our Professional object:
Time to create Prototype object:
Now, let's instantiate our objects and show the output:
Finalize
Prototype helps you create prototype instances of the objects and lets you clone them. It's widely used in Javascript especially in jQuery library.
According to DoFactory,a prototype factory has three objects:

- Client stage: The execution of the creation of objects.User creates the prototype object here.
- Prototype: A class derived from another class with clone function in which you can use same object in another place.
- Clones: The objects created from Prototype.

My Prototype example has the same amount of objects as DoFactory's.
Professional Object
ProfessionalPrototype Object
Clone Object
We shall create Professionals from Prototype and then create clones.
Let's see some code!
Implementation
Let's create our Professional object:
- var Professional = WinJS.Class.define(
- function(name, job, age) {
- this.name = name;
- this.job = job;
- this.age = age;
- this.say = WinJS.Class.define(
- function () {
- console.log(this.name + " is working as " + this.job +
- " who is " + this.age + " years old");
- });
- });
- var ProfessionalPrototype = WinJS.Class.define(
- function(proto) {
- this.proto = proto;
- this.clone = WinJS.Class.derive(Professional,function(){
- var prof = new Professional();
- prof.name = proto.name;
- prof.job = proto.job;
- prof.age = proto.age;
- return prof;
- });
- });
- var proto = new Professional("Ibrahim Ersoy", "Developer", "31");
- var prototype = new ProfessionalPrototype(proto);
- prof.say();

Bhuvanesh MohankumarPosted May 30, 2016, 1:18 PM
Good one
Vignesh ManiPosted May 30, 2016, 9:28 AM
Nice one
RajaPosted May 30, 2016, 2:42 AM
Good One..
Thiruppathi RPosted May 30, 2016, 1:34 AM
Nice ..
Debasis SahaPosted May 30, 2016, 1:13 AM
Nice share..