//every object has internal property call prototype.//prototype is simple reference to another object that//contain common attributes and methods which will save memeory functionTodo(name,completed){this.name=name;this.completed= completed;}Todo.prototype.getTodoName=function(){console.log(this.name)}const todo=newTodo("Buy Eggs",false);const todo2=newTodo("Learn javascript",false);
todo.getTodoName();console.log(todo,todo2);//at console getTodoName will be inside prototype which will save memeory
*Prototype-Every object inJavaScript has a built-in property,
which is called its prototype.-The prototype is itself an object, so the prototype will
have its own prototype, making what iss called a prototype chain.-The chain ends when we reach a prototype that has nullfor
its own prototype.-Prototypes are the mechanism by which JavaScript objects inherit
features from one another
const arr =[1,2,3,4]// proto type : arr.__proto__// prototype chain : arr.__proto__.__proto__.__proto__
// prototypes in javascript, THey create new Methods to our constructor functionconstEmployersInfo=function(name , salary , bonusPercentage){this.name= name ;this.salary= salary;this.bonusPercentage= bonusPercentage;}// prototype for getting the employer credentialEmployersInfo.prototype.credentialInfo=function(){return`${this.name} Has a base salary of ${this.salary}`;}EmployersInfo.prototype.getBonus=function(){let bonusAmount =(this.salary*(this.bonusPercentage));return`${this.name} earned ${bonusAmount} Bonus`;}// let's first create the instance of employerInformconst employerInform =newEmployersInfo('kevin',12000,12);// logging employerInformconsole.log(employerInform);// logging the credentials console.log(employerInform.credentialInfo());// logging the Bonus function console.log(employerInform.getBonus());2Show6MoreGrepperResults
/*Prototype is used to add properties/methods to a
constructor function as in example below */functionConstructorFunction(name){this.name= name //referencing to current executing object}ConstructorFunction.prototype.age=18let objectName =newConstructorFunction("Bob")console.log(objectName.age)//18
//every object has internal property call prototype.//prototype is simple reference to another object that//contain common attributes and methods which will save memeory functionTodo(name,completed){this.name=name;this.completed= completed;}Todo.prototype.getTodoName=function(){console.log(this.name)}const todo=newTodo("Buy Eggs",false);const todo2=newTodo("Learn javascript",false);
todo.getTodoName();console.log(todo,todo2);//at console getTodoName will be inside prototype which will save memeory
#include<iostream>
using namespace std;// Function prototype// type function-name (arguments);// int sum(int a, int b); //--> Acceptable// int sum(int a, b); //--> Not Acceptable
int sum(int, int);//--> Acceptable // void g(void); //--> Acceptable voidg();//--> Acceptable
int main(){
int num1, num2;
cout<<"Enter first number"<<endl;
cin>>num1;
cout<<"Enter second number"<<endl;
cin>>num2;// num1 and num2 are actual parameters
cout<<"The sum is "<<sum(num1, num2);g();return0;}
int sum(int a, int b){// Formal Parameters a and b will be taking values from actual parameters num1 and num2.
int c = a+b;return c;}voidg(){
cout<<"
Hello,GoodMorning";}