Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created February 7, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrolechuga/757582057e0a8810e53dac1268961d42 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/757582057e0a8810e53dac1268961d42 to your computer and use it in GitHub Desktop.
ejemplo cadena proto
var a = {
valor: 'Hola'
};
var b = {
proto: a
};
var c = {
proto: b
};
var d = {
proto: c
};
var e = {
proto: d
};
function lookup(key, objeto) {
var next = objeto;
while(!!next) {
if (key in next) {
return next[key];
} else {
next = next.proto;
}
}
return undefined;
}
// operacion
console.log(lookup('valor', e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment