Created
December 4, 2014 20:21
-
-
Save topicus/61d0ab782b48001b225a 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
'use strict'; | |
function MiConstructor(){ | |
// Guardamos la referencia a this en la variable self | |
var self = this; | |
window.scopeGlobal = 10; | |
var scopeLocal = 11; | |
var miArray = [2,10,2,3]; | |
// Apunta correctamente a MiConstructor | |
console.log(self); | |
this.mimetodo = function(){ | |
// Apunta correctamente a MiConstructor | |
console.log(self); | |
miArray.forEach(function(item){ | |
// Ahora apunta correctamente a MiConstructor | |
console.log(self); | |
}); | |
} | |
} | |
var ct = new MiConstructor(); | |
ct.mimetodo(); | |
console.log(window.scopeGlobal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment