Eloquent JavaScript 9 methods

by Joe LeMonnier

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

var smap = {};
function storesPhi(event, phi) {
  smap[event] = phi;
}

storesPhi("spizza", 0.069);
storesPhi("stouched tree", -0.081);




var map = {};
function storePhi(event, phi) {
  map[event] = phi;
}

storePhi("pizza", 0.069);
storePhi("touched tree", -0.081);

console.log(map); 
document.write('<br>TNew',map.pizza);



Object.prototype.nonsense = "hi";
for ( n in map)
  console.log(n);
// → pizza
// → touched tree
// → nonsense
console.log("nonsense" in map);
// → true
console.log("toString" in map);
// → true

console.log(map.nonsense);
console.log(smap.nonsense);

// Delete the problematic property again
delete Object.prototype.nonsense; 

for(n in map)
  console.log(n);
// → pizza
// → touched tree
// → nonsense
console.log('nonsense 'in map);