Skip to content

Instantly share code, notes, and snippets.

@khadorkin
Forked from skarankevich/01_closure.js
Created September 27, 2016 09:54
Show Gist options
  • Save khadorkin/9131b8b13d6855d7dda1ea615c9faaf5 to your computer and use it in GitHub Desktop.
Save khadorkin/9131b8b13d6855d7dda1ea615c9faaf5 to your computer and use it in GitHub Desktop.
FE Test
(function() {
console.log(abc);
var abc = "abc";
console.log(myFunc());
function myFunc() {
var def = abc + 'def';
return def;
}
})();
function loop() {
for (var i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, i * 1000);
}
}
loop();
(function() {
console.log(1);
setTimeout(function() {
console.log(2);
}, 1000);
setTimeout(function() {
console.log(3);
}, 0);
console.log(4);
})();
// Array.prototype.map
var persons = [
{
id: 1,
name: "John Smith",
},
{
id: 2,
name: "Sam Nilson",
},
...
];
function getNames(persons) {
...
}
console.log(getNames(persons));
// [{
// id: 1,
// firstName: "John",
// lastName: "Smith"
// }, ...]
// Array.prototype.filter & Array.prototype.every
var numbers = [2, 4, 6, 7, 8, 10, 13];
function getOddNumbers(numbers) { // нечетные
...
}
var oddNumbers = getOddNumbers(numbers); // array
function isAllNotBiggerThan100(numbers) {
...
}
var isNotBiggerThan100 = isAllNotBiggerThan100(numbers); // boolean
function func() {
this.name = "John";
}
var a = func(); // a? this?
var b = new func(); // b? this?
var c = {
name: "Sam", // writable: false
sayName: function () {
console.log(this.name);
}
}
var d = ...;
d(); // => "John"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment