Skip to content

Instantly share code, notes, and snippets.

View haingdc's full-sized avatar

Hai.Nguyen Github haingdc

View GitHub Profile
@haingdc
haingdc / finalPonies.js
Created February 28, 2018 11:10
A Gentle Introduction to Functional JavaScript: Part 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="pony-list-wrapper"></div>
@haingdc
haingdc / sing.js
Created March 13, 2018 04:43
A Gentle Introduction to Functional JavaScript: Part 3
var thing = 'bat';
var sing = function() {
// Bên trong ‘sing’ có thể thấy biến line
var line = 'Twinkle, twinkle, little ' + thing;
console.log(line);
};
sing();
// Twinkle, twinkle, little bat
@haingdc
haingdc / inner.js
Created March 13, 2018 04:45
A Gentle Introduction to Functional JavaScript: Part 3
var outer = function() {
var outerVar = 'Hatter';
var inner = function() {
// Hàm trong ‘inner’ có thể thấy biến outerVar
console.log(outerVar);
// Hatter
var innerVar = 'Dormouse';
// 🌳🌳🦍🌄 phạm vi của innerVar là trong hàm inner, bên ngoài không thể thấy
}
@haingdc
haingdc / showArgs.js
Created March 13, 2018 04:46
A Gentle Introduction to Functional JavaScript: Part 3
var showArgs = function(a, b) {
console.log(arguments);
}
showArgs('Tweedledee', 'Tweedledum');
//=> { '0': 'Tweedledee', '1': 'Tweedledum' } (🌟)
@haingdc
haingdc / lestMore.js
Created March 13, 2018 04:46
A Gentle Introduction to Functional JavaScript: Part 3
// đối số ít hơn tham số
showArgs('less');
//=> { 0: "less" }
// đối số nhiều hơn tham số
showArgs('a', 'l', 'i', 'c', 'e');
//=> { '0': 'a', '1': 'l', '2': 'i', '3': 'c', '4': 'e' }
@haingdc
haingdc / length.js
Created March 13, 2018 04:47
A Gentle Introduction to Functional JavaScript: Part 3
var argsLen = function() {
console.log(arguments.length);
}
argsLen('a', 'l', 'i', 'c', 'e');
//=> 5
@haingdc
haingdc / twinkleTwinkle.js
Created March 13, 2018 04:48
A Gentle Introduction to Functional JavaScript: Part 3
function twinkleTwinkle(thing) {
console.log('Twinkle, twinkle, little ' + thing);
}
twinkleTwinkle('bat');
//=> Twinkle, twinkle, little bat
@haingdc
haingdc / twinkleCall.js
Created March 13, 2018 04:49
A Gentle Introduction to Functional JavaScript: Part 3
twinkleTwinkle.call(null, 'star');
//=> Twinkle, twinkle, little star
@haingdc
haingdc / twinkleApply.js
Created March 13, 2018 04:50
A Gentle Introduction to Functional JavaScript: Part 3
twinkleTwinkle.apply(null, ['bat']);
//=> Twinkle, twinkle, little bat
@haingdc
haingdc / doubleArray.js
Created March 13, 2018 04:51
A Gentle Introduction to Functional JavaScript: Part 3
var numbers = [1, 2, 3];
var doubledArray = map(function(x) { return x * 2}, numbers);
console.log(doubledArray);
//=> [ 2, 4, 6 ]