Prototype

A fully initialized instance to be copied or cloned

  • Create an object using a prototypical instance, and create new objects by copying this prototype.

  • It's usage is high in javascript.

EX:
function CustomerPrototype(proto) {
    this.proto = proto;
 
    this.clone = function () {
        var customer = new Customer();
 
        customer.first = proto.first;
        customer.last = proto.last;
        customer.status = proto.status;
 
        return customer;
    };
}
 
function Customer(first, last, status) {
 
    this.first = first;
    this.last = last;
    this.status = status;
 
    this.say = function () {
        alert("name: " + this.first + " " + this.last +
              ", status: " + this.status);
    };
}
 
function run() {
 
    var proto = new Customer("n/a", "n/a", "pending");
    // creates without references.
    var prototype = new CustomerPrototype(proto);
 
    var customer = prototype.clone();
    customer.say();
}

Last updated