All about JavaScript Prototype.. Evolution of new, this and class keyword in JavaScript….

const person={
name:"Rayhan",
age:10,
height: 5
}
const student = Object.create(person);
console.log(student) //{}
console.log(student.name) //Rayhan
const methodOfProgrammer={
coding(){
console.log("I am coding")},
debugging(){
console.log("I am Debugging problem")},
sleep(){
console.log("Problem is solved. Sleeping")},
}
function Programmer(name,programmingLanguage){
let programmer = Object.create(methodOfProgrammer);
programmer.name=name;
programmer.age=age;
return programmer;
}
const kabir = Programmer("Kabir","JavaScript");
kabir.coding() // I am coding
function Programmer(name,programmingLanguage){
let programmer = Object.create(programmer.prototype);
programmer.name=name;
programmer.age=age;
return programmer;
}
Programmer.prototype={
coding(){
console.log("I am coding")},
debugging(){
console.log("I am Debugging problem")},
sleep(){
console.log("Problem is solved. Sleeping")},
}
const kabir = Programmer("Kabir","JavaScript");const sabbir = Programmer("Sabbir","python");
kabir.coding(); // I am coding
  1. “Programmer” is a constructor function because by that we have created objects . As it has constructed object, for this reason it is a constructor. In JavaScript all functions are constructor. By convention the name of a constructor function should be stated with capital letter.
  2. How we can add method in the prototype of a constructor function.
  3. How we can take the property of parent in child by Object.create() method
function Programmer(name,programmingLanguage){
let programmer = Object.create(programmer.prototype);
programmer.name=name;
programmer.age=age;
return programmer;
}
Programmer.prototype={
coding(){
console.log("I am coding")},
debugging(){
console.log("I am Debugging problem")},
sleep(){
console.log("Problem is solved. Sleeping")},
}
const kabir = Programmer("Kabir","JavaScript");
const sabbir = Programmer("Sabbir","python");
kabir.coding(); // I am coding
--------------------------------------------------------------------
function Programmer(name,programmingLanguage){

this.name=name;
this.age=age;

}
Programmer.prototype={
coding(){
console.log("I am coding")},
debugging(){
console.log("I am Debugging problem")},
sleep(){
console.log("Problem is solved. Sleeping")},
}
const kabir = new Programmer("Kabir","JavaScript");
const sabbir = new Programmer("Sabbir","python");
kabir.coding(); // I am coding
function Programmer(name,programmingLanguage){

this.name=name;
this.age=age;

}
Programmer.prototype={
coding(){
console.log("I am coding")},
debugging(){
console.log("I am Debugging problem")},
sleep(){
console.log("Problem is solved. Sleeping")},
}
const kabir = new Programmer("Kabir","JavaScript");
const sabbir = new Programmer("Sabbir","python");
kabir.coding(); // I am coding
--------------------------------------------------------------------
class Programmer{
constructor(name,age){
this.name=name;
this.age=age;
}
coding(){
console.log("I am coding")
}
debugging(){
console.log("I am Debugging problem")
}
sleep(){
console.log("Problem is solved. Sleeping")
}
}
const kabir = new Programmer("Kabir","JavaScript");
const sabbir = new Programmer("Sabbir","python");
kabir.coding(); // I am coding

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Md Solayman

Md Solayman

An enthusiastic learner , currently focused on Web Development using HTML, CSS, Bootstrap, JavaScript , React, Node, Express Js, Mogodb.