javascript function prototype code example
Example 1: javascript prototype explained
function Student() {
this.name = 'John';
this.gender = 'M';
}
Student.prototype.age = 15;
var studObj1 = new Student();
alert(studObj1.age);
var studObj2 = new Student();
alert(studObj2.age);
Example 2: function prototype javascript
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var person = new Person("John Doe");
person.getName()
Example 3: prototype javascript
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Person.prototype.nationality = "English";
var myFather = new Person("John", "Doe", 50, "blue");
console.log("The nationality of my father is " + myFather.nationality)
Example 4: function prototype
void add(int, int);
int main() {
add(5, 3);
return 0;
}
void add(int a, int b) {
cout << (a + b);
}
Example 5: what is the function prototype for fputs()
int fputs(const char *string,FILE *filename);