Horje
javascript prototype vs constructor function Code Example
javascript prototype vs constructor function
function Class () {}
Class.prototype.calc = function (a, b) {
    return a + b;
}

// Create 2 instances:
var ins1 = new Class(),
    ins2 = new Class();

// Test the calc method:
console.log(ins1.calc(1,1), ins2.calc(1,1));
// -> 2, 2

// Change the prototype method
Class.prototype.calc = function () {
    var args = Array.prototype.slice.apply(arguments),
        res = 0, c;

    while (c = args.shift())
        res += c;

    return res; 
}

// Test the calc method:
console.log(ins1.calc(1,1,1), ins2.calc(1,1,1));
// -> 3, 3




Javascript

Related
find element at ith index js overflow Code Example find element at ith index js overflow Code Example
get item in array from index Code Example get item in array from index Code Example
how to get checkbox value in jquery Code Example how to get checkbox value in jquery Code Example
href before onclick js Code Example href before onclick js Code Example
js string includes count Code Example js string includes count Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9