Skip to content

Commit b34be10

Browse files
committed
Added JavaScript IIFE, this, call and apply examples
1 parent 4ecca6c commit b34be10

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

JavaScript/9-this.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
let city = {
4+
name: 'Kiev',
5+
year: 482,
6+
f1: function() {
7+
return this.name;
8+
},
9+
f2: () => {
10+
return this.name;
11+
}
12+
};
13+
14+
console.log('city.f1() = ' + city.f1());
15+
console.log('city.f2() = ' + city.f2());

JavaScript/a-iife.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
// Immediately-invoked function expression
4+
5+
(function f1() {
6+
console.log('f1');
7+
})();
8+
9+
(function() {
10+
console.log('anonymous');
11+
})();
12+
13+
(() => {
14+
console.log('lambda');
15+
})();
16+
17+
{
18+
console.log('block');
19+
}

JavaScript/b-call-apply.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
// Immediately-invoked function expression
4+
5+
function f1(a, b) {
6+
console.log('f1(' + a + ', ' + b + ')');
7+
}
8+
9+
f1.call(null, 2, 3);
10+
f1.apply(null, [2, 3]);

0 commit comments

Comments
 (0)