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
| ;(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
| 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
| 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 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
| // 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); | |
| } | |
| ); |
NewerOlder