Skip to content

Instantly share code, notes, and snippets.

@topicus
Created December 4, 2014 20:21
Show Gist options
  • Save topicus/61d0ab782b48001b225a to your computer and use it in GitHub Desktop.
Save topicus/61d0ab782b48001b225a to your computer and use it in GitHub Desktop.
'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