Skip to content

Instantly share code, notes, and snippets.

View haingdc's full-sized avatar

Hải haingdc

View GitHub Profile
@haingdc
haingdc / iife_pattern1.js
Created January 30, 2018 10:01
iife patterns
(function () {
// ...
})();
@haingdc
haingdc / block_scope.js
Created January 30, 2018 10:05
block scope
{
// các câu lệnh
}
tên_nhãn: {
// các câu lệnh
}
@haingdc
haingdc / iife_example.js
Created January 30, 2018 10:07
iife example
var a = 2;
(function foo(){
var a = 3;
console.log( a ); // 3
})();
console.log( a ); // 2
@haingdc
haingdc / iife_absence.js
Created January 30, 2018 10:09
iife without-iife
var person = "Alice";
var fruit = "apple";
var fruits = [
"banana",
"lemon",
"mango",
"peace"
];
@haingdc
haingdc / iife_presence.js
Created January 30, 2018 10:11
iife presence
var person = "Alice";
var fruit = "apple";
var fruits = [
"banana",
"lemon",
"mango",
"peace"
];
@haingdc
haingdc / closure_affect.js
Created January 30, 2018 10:14
close affect
var result = [];
for (var year = 0; year < 5; year++) {
result.push(function () { return year }); // (1)
}
console.log(result[1]()); // 5 (không phải 1)
console.log(result[3]()); // 5 (không phải 3)
@haingdc
haingdc / iife_handle_closure_affect_step_1.js
Last active January 30, 2018 10:18
handle closure affect by iife step 1
var result = [];
for(var year = 0; year < 5; year++) {
var y = year; // (2)
result.push(function() { return y; }); // (3)
}
console.log(result[1]()); // 4 (không phải 1)
console.log(result[3]()); // 4 (không phải 3)
@haingdc
haingdc / iife_handle_closure_affect_step_2.js
Created January 30, 2018 10:20
handle closure affect by iife step 2
var result = [];
for(var year = 0; year < 5; year++) {
(function() {
var y = year;
result.push(function() { return y; });
})();
}
console.log(result[1]()); // 1
console.log(result[3]()); // 3
@haingdc
haingdc / myContainer.js
Created February 24, 2018 14:13
A Gentle Introduction to Functional JavaScript: Part 1
var myContainer = “Hey everybody! Come see how good I look!”;
@haingdc
haingdc / log.js
Created February 24, 2018 14:15
A Gentle Introduction to Functional JavaScript: Part 1
function log(someVariable) {
console.log(someVariable);
return someVariable;
}