-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (98 loc) · 2.87 KB
/
script.js
File metadata and controls
127 lines (98 loc) · 2.87 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//function constructor
/*
var Person = function(name, age, height, weight, isMarried){
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
this.isMarried = isMarried;
}
Person.prototype.calculateRetireAge = function(){
return 65 - this.age;
}
var navdeep = new Person('Navdeep', 29, 172,72,true);
var james = new Person('James', 29, 172,72,true);
console.log(navdeep.name,navdeep.age,'Retires in ', navdeep.calculateRetireAge());
*/
//function callback
/*
var birthYear = [1990, 1960, 1950, 1999, 1960, 2000];
var calculate = function (arr, fn){
var result = [];
for(var i =0;i<arr.length;i++){
result[i]=fn(arr[i]);
}
return result
}
var calculateAge = function(el){
return 2019-el;
}
var calculateHeartRisk = function(age){
if(age>=65){
return true;
}
return false;
}
var age = calculate(birthYear,calculateAge);
//console.log(calculate(birthYear,calculateAge));
console.log(calculate(age,calculateHeartRisk));
*/
//function returns function
/*
var interviewQuestions = function (job){
switch (job) {
case 'teacher':
return function(name){ console.log(name + ' what do you do in your job '+job)}
case 'plumber':
return function(name){ console.log(name + ' what do you do in your job '+job)}
default:
return function(name){ console.log(name + ' what do you learn ');}
}
}
//closure function.. inner function.
function interviewQues(job){
var additionVal='Additional Perk Given.'
return function(name){
switch (job) {
case 'teacher':
console.log(name + ' what do you do in your job '+job+' '+ additionVal)
break;
case 'plumber':
console.log(name + ' what do you do in your job '+job+' '+ additionVal)
break;
default:
console.log(name + ' what do you learn '+' '+ additionVal)
}
}
}
interviewQues('plumber')('John');
//interviewQuestions('teacher')('navdeep')
*/
//bind call apply
var john = {
name:'John',
age : 25,
presentation:function(skill,timeOfDay){
console.log('Hi '+this.name+
'. My age is '+this.age+'. '+
' I am a '+skill+'. '+' Have a good '+timeOfDay);
},
jogging:function(arr){
for(var i =0;i<arr.length;i++){
console.log(' moving '+arr[i]+' steps further')
}
}
}
//john.presentation('Software Engineer','Morning')
var emily ={
name:'Emily',
age: 23
}
//john.presentation.call(emily,'teacher','evening');
john.presentation.apply(emily,['Plumber','Night']);
var johnSkill = john.presentation.bind(john,'teacher')
johnSkill('morning')
johnSkill('afternoon')
johnSkill('evening')
var emilySkill = john.presentation.bind(emily,'Software Engineer')
emilySkill('evening')