This file contains 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
//Using a new object | |
var Order = function(id) { | |
//we ignore ‘this’ altogether… it’s evil right? | |
var that = {}; | |
that.id = id; | |
return that; | |
}; | |
… | |
var order = new Order(1); |
This file contains 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
//Using a new object | |
var Order = function(id) { | |
//we ignored (this) but avoided using an extra variable (that) | |
return { | |
id: id | |
}; | |
}; | |
… | |
var order = new Order(1); |
This file contains 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 (parameter1, parameter2) { | |
//your code here | |
}) (a, b) |
This file contains 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 closureFn = function(parameter1, parameter2) { | |
//your code here | |
} | |
… | |
var a, b; | |
closureFn(a, b); | |
… |
This file contains 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 buggy() { | |
for ( var i = 0; i < 5; i++ ) { | |
console.log(“Delay: “, i*100); | |
setTimeout(function() { | |
console.log(“i:”, i) | |
}, i * 100 ); | |
} | |
} |
This file contains 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 fixed() { | |
for ( var i = 0; i < 5; i++ ) { | |
console.log(“Delay: “, i*100); | |
(function(safe_i) { | |
setTimeout(function() { | |
console.log(“i:”, safe_i) | |
}, i * 100 ); | |
}) (i); | |
} | |
} |
This file contains 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 buggy() { | |
for ( var i = 0; i < 5; i++ ) { | |
console.log(“Delay: “, i*100); | |
setTimeout(function() { | |
console.log(“i:”, i) | |
}, i * 100 ); | |
} | |
} |
This file contains 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 fixed() { | |
for ( var i = 0; i < 5; i++ ) { | |
console.log(“Delay: “, i*100); | |
(function(safe_i) { | |
setTimeout(function() { | |
console.log(“i:”, safe_i) | |
}, i * 100 ); | |
}) (i); | |
} | |
} |
This file contains 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
.config(function($httpProvider, $translateProvider) { | |
… //seen before | |
}) | |
// Service definition | |
.factory(‘Language’, function ($translate) { | |
//add the languages you support here. ar stands for arabic | |
var rtlLanguages = [‘ar’]; | |
var isRtl = function() { |
This file contains 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
//language module | |
angular.module(‘myapp.language’, [‘pascalprecht.translate’]) | |
.config(function($httpProvider, $translateProvider) { | |
… //seen before | |
}) | |
// Service definition | |
.factory(‘Language’, function ($translate) { | |
//add the languages you support here. ar stands for arabic |