-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototypeinherit.js
More file actions
58 lines (51 loc) · 1.63 KB
/
Copy pathprototypeinherit.js
File metadata and controls
58 lines (51 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//It is an old method and is not used now but we have some knowledge about that.
//In this we are going to define an object .
// const proto={
// slogan:function()
// {
// return("This company is the best")
// },
// changename:function(newName)
// {
// this.name=newName;
// }
// }
//1-
//It will create an object.
// const pro=Object.create(proto)
// pro.changename="Danish"
// pro.name="Danish"
// pro.role="Coder"
// console.log(harry)
//2-
//It is a complex statement as we are not going to use in other tutorials.
//This will also creates an object
// const harry=Object.create(proto,{
// name:{value:'Danish',writable:true},//writable:true means that we can change this name even if it is of const harry element.
// class:{value:'Coding'},
// })
// harry.changename("Dani")//It will change the name beacuse in name we haveused writable:true;
// console.log(harry)
//3-Inheritence
//i-
function employ(company,salary,passion)
{
this.company=company;
this.salary=salary;
this.passion=passion;
}
employ.prototype.slogan=function()
{
return(`My worship: . ${this.company}`)
}
let objj=new employ("Google",342423,"Coder")
console.log(objj)
//ii-
function bhai(company,salary,passion,language)
{
employ.call(this,company,salary,passion);//This will inherit all these 4 arguements from employ object by employ.call(parameters).Also use this as the first arguement
this.language=language;
}
bhai.prototype=Object.create(employ.prototype)//It will get the slogan from employ and put it to bhai.
let danish=new bhai("Micosoft",20000,"Game Developer","Python")//Use let in starting.
console.log(danish)