Answers for "prototype"

13

javascript prototype explained

/* Answer to: "javascript prototype explained" */

/*
  The prototype object is special type of enumerable object to
  which additional properties can be attached to it which will be
  shared across all the instances of it's constructor function.

  So, use prototype property of a function in the above example
  in order to have age properties across all the objects as
  shown below:
*/

function Student() {
    this.name = 'John';
    this.gender = 'M';
}

Student.prototype.age = 15;

var studObj1 = new Student();
alert(studObj1.age); // 15

var studObj2 = new Student();
alert(studObj2.age); // 15
Posted by: Guest on April-18-2020
0

prototype meaning

String    Number.0.97.8.582..6985849
90.864.2.3.4.1..5785.9.6..77
Posted by: Guest on July-05-2021
0

prototype

String.prototype.countCharacter = function(char) {
    return [...this].filter(c => c === char).length;
}
Posted by: Guest on December-28-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language