Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0575a1

Browse files
author
Ashfaq
committed
intermediate commit
1 parentab31a4c commita0575a1

File tree

2 files changed

+117
-87
lines changed

2 files changed

+117
-87
lines changed

‎Objects/Objects.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* use strict */
2+
varobj1={
3+
name:"cat"
4+
};
5+
6+
varobj2=Object.create({});
7+
8+
varobj3=Object.create({name:"cat"});
9+
10+
debugger;
11+
12+
console.log(obj1,obj2,obj3);
13+
14+
/*
15+
* An Object have 4 properties
16+
* 1. Values:
17+
* 2. Flags:
18+
* a.) writable: if true you can update the property otherwise readOnly; {this can be reconfigured}
19+
* b.) configurable: if true you can delete update and change the property; {}
20+
* c.) enumerable: if true you will get this property while looping over it otherwise not;
21+
*/

‎closures.js‎

Lines changed: 96 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,100 @@
1-
functiongreet(whatToSay){
2-
returnfunction(name){
3-
console.log(`${whatToSay} :${name}`)
1+
// function greet(whatToSay) {
2+
// return function(name) {
3+
// console.log(`${whatToSay} : ${name}`);
4+
// };
5+
// }
6+
7+
// greet("Hi")("ashfaq");
8+
9+
// var sayHi = greet("Hi");
10+
// // function have access to lexically scoped variable and function when it is invoked outside of the scope{execution context}
11+
12+
// sayHi("Kranthi");
13+
14+
// function build() {
15+
// var arr = [];
16+
// for (var i = 0; i < 3; i++) {
17+
// arr.push(function() {
18+
// console.log(i);
19+
// });
20+
// }
21+
// return arr;
22+
// }
23+
24+
// var fs = build();
25+
26+
// fs[0](); //3
27+
// fs[1](); //3
28+
// fs[2](); //3
29+
30+
// // solution1 Old school By using IIFE
31+
// function build2() {
32+
// var arr = [];
33+
// for (var i = 0; i < 3; i++) {
34+
// arr.push(
35+
// (function(j) {
36+
// return function() {
37+
// console.log(j);
38+
// };
39+
// })(i)
40+
// );
41+
// }
42+
// return arr;
43+
// }
44+
45+
// var fs2 = build2();
46+
47+
// fs2[0](); //3
48+
// fs2[1](); //3
49+
// fs2[2](); //3
50+
51+
// // ES6 solution By using let
52+
53+
// function build3() {
54+
// var arr = [];
55+
// for (let i = 0; i < 3; i++) {
56+
// arr.push(function() {
57+
// console.log(i);
58+
// });
59+
// }
60+
// return arr;
61+
// }
62+
63+
// var fs3 = build3();
64+
65+
// fs3[0](); //0
66+
// fs3[1](); //1
67+
// fs3[2](); //2
68+
69+
// // KYLE SIMPSON deep javascript //
70+
// // closure is preservation of linkage of variable not value
71+
72+
// var teacher = "kyle";
73+
74+
// var myTeacher = function() {
75+
// console.log(teacher);
76+
// };
77+
78+
// teacher = "Simpson";
79+
80+
// myTeacher();
81+
82+
functiontest(){
83+
vardata="SDSD";
84+
functiontest1(){
85+
return(data=1+data);
486
}
5-
}
6-
7-
greet('Hi')('ashfaq');
8-
9-
varsayHi=greet('Hi');
10-
// function have access to lexically scoped variable and function when it is invoked outside of the scope{execution context}
11-
12-
sayHi("Kranthi");
13-
14-
15-
16-
17-
functionbuild(){
18-
vararr=[];
19-
for(vari=0;i<3;i++){
20-
arr.push(
21-
function(){
22-
console.log(i)
23-
}
24-
)
87+
functiontest2(){
88+
return(data=2+data);
2589
}
26-
returnarr;
27-
}
28-
29-
varfs=build();
30-
31-
fs[0]();//3
32-
fs[1]();//3
33-
fs[2]();//3
34-
35-
36-
// solution1 Old school By using IIFE
37-
functionbuild2(){
38-
vararr=[];
39-
for(vari=0;i<3;i++){
40-
arr.push(
41-
(function(j){
42-
returnfunction(){
43-
console.log(j)
44-
}
45-
}(i))
46-
)
47-
}
48-
returnarr;
49-
}
50-
51-
varfs2=build2();
52-
53-
fs2[0]();//3
54-
fs2[1]();//3
55-
fs2[2]();//3
56-
57-
58-
// ES6 solution By using let
59-
60-
61-
functionbuild3(){
62-
vararr=[];
63-
for(leti=0;i<3;i++){
64-
arr.push(
65-
function(){
66-
console.log(i)
67-
}
68-
)
90+
functiontest3(){
91+
return(data=3+data);
6992
}
70-
returnarr;
93+
return{
94+
test1,
95+
test2,
96+
test3
97+
};
7198
}
72-
73-
varfs3=build3();
74-
75-
fs3[0]();//0
76-
fs3[1]();//1
77-
fs3[2]();//2
78-
79-
80-
// KYLE SIMPSON deep javascript //
81-
// closure is preservation of linkage of variable not value
82-
83-
varteacher="kyle";
84-
85-
varmyTeacher=function(){
86-
console.log(teacher)
87-
}
88-
89-
teacher="Simpson"
90-
91-
myTeacher()
99+
letz=test();
100+
console.log(z.test1(),z.test2(),z.test3());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp