Answers for "prototype of a function can be used to"

C
0

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
Posted by: Guest on June-15-2020
0

what is the function prototype for fputc()

int fputc(const char ch, FILE *filename);
Posted by: Guest on April-27-2020

Code answers related to "prototype of a function can be used to"

Code answers related to "C"

Browse Popular Code Answers by Language