Last active
August 29, 2015 14:01
-
-
Save anasnakawa/b0bc4ee1149fefbd23e6 to your computer and use it in GitHub Desktop.
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 Car() { | |
this.array = []; | |
this.log = function() {} | |
} | |
Car.prototype.something = function() { | |
var self = this; // <- fine | |
this.array.forEach( function(item) { | |
self.log( item ); | |
}); | |
} |
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 self; // <- bad | |
function Car() { | |
this.array = []; | |
this.log = function() {} | |
} | |
Car.prototype.something = function() { | |
self = this; | |
this.array.forEach( function(item) { | |
self.log( item ); | |
}); | |
} |
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() { | |
var self; // <- really bad | |
function Car() { | |
this.array = []; | |
this.log = function() {} | |
} | |
Car.prototype.something = function() { | |
self = this; | |
this.array.forEach( function(item) { | |
self.log( item ); | |
}); | |
} | |
window.Car = Car; | |
})(); |
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() { | |
function Car() { | |
this.array = []; | |
this.log = function() {} | |
} | |
Car.prototype.something = function() { | |
self = this; // omiting var in non `strict-mode`, will let variable became global | |
this.array.forEach( function(item) { | |
self.log( item ); | |
}); | |
} | |
window.Car = Car; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment