Have migrated to this repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // same execution context, all pointing to same memory location | |
| // so by the time running console.log(i), i will be its final value (i.e. 3) | |
| function buildFunctions() { | |
| var arr = []; | |
| for (var i = 0; i < 3; i++) { | |
| arr.push( | |
| function () { | |
| console.log(i); | |
| } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeGreeting(language) { | |
| return function (name) { | |
| if (language == 'en') { | |
| console.log('Hello ' + name); | |
| } | |
| else if (language == 'es') { | |
| console.log('Hola ' + name); | |
| } | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var person = { | |
| firstname: 'John', | |
| lastname: 'Doe', | |
| getFullName: function() { | |
| return this.firstname + ' ' + this.lastname; | |
| } | |
| } | |
| var logName = function(arg1, arg2) { | |
| console.log('Logged: ' + this.getFullName()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mapForEach(array, fn) { | |
| var tmpArr = []; | |
| for (var i = 0; i < array.length; i++) { | |
| tmpArr.push( | |
| fn(arr[i]) | |
| ); | |
| } | |
| return tmpArr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(function(global, $) { | |
| // 'new' an object | |
| var Greetr = function(firstName, lastName, language) { | |
| return new Greetr.init(firstName, lastName, language); | |
| } | |
| // hidden within the scope of the IIFE and never directly accessible | |
| var supportedLangs = ['en', 'es']; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fibonacci = function(number) { | |
| var mem = {}; | |
| function f(n) { | |
| var value; | |
| if (n in mem) { | |
| value = mem[n]; | |
| } | |
| else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Simulate classical ineritance (not recommended) using constructor function | |
| */ | |
| function Greeter (name) { | |
| this.name = name || 'John Doe'; | |
| } | |
| Greeter.prototype.hello = function hello () { | |
| return 'Hello, my name is ' + this.name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const proto = { | |
| hello: function hello() { | |
| return `Hello, my name is ${ this.name }`; | |
| } | |
| }; | |
| const george = Object.assign({}, proto, {name: 'George'}); | |
| const msg = george.hello(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const animals = [ | |
| { | |
| "name": "cat", | |
| "size": "small", | |
| "weight": 5 | |
| }, | |
| { | |
| "name": "dog", | |
| "size": "small", | |
| "weight": 10 |
OlderNewer