Skip to content

Instantly share code, notes, and snippets.

@jherax
Created May 26, 2015 03:14
Show Gist options
  • Save jherax/9eebe65482d8fa696a41 to your computer and use it in GitHub Desktop.
Save jherax/9eebe65482d8fa696a41 to your computer and use it in GitHub Desktop.
JavaScript: Eliminar propiedades
(function() {
//verificamos cual es el ámbito global
//(generalmente el objeto window)
console.log("Global scope", this);
var x = 42; //variable local
var point = { x: 10, y: 15 }; //objeto local
//si no se especifica el keyword "var",
//se crea como una propiedad del objeto global
z = 100;
//método del objeto global
func = function() {
var n = 5;
console.log("delete n:", delete n); //-> false
//no se elimina porque es una variable local
return n;
};
//ejecutamos el método global
func();
//intentamos eliminar las propiedades
console.log("delete x:", delete x); //-> false
console.log("delete z:", delete z); //-> true
console.log("delete point:", delete point); //-> false
console.log("delete point.x:", delete point.x); //-> true
console.log("delete func:", delete func); //-> true
//"func" y "z" se pudieron eliminar porque son parte
//del objeto global, es decir: window.func y window.z
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment