Skip to content

Instantly share code, notes, and snippets.

@mingtsay
Created June 20, 2014 07:37
Show Gist options
  • Save mingtsay/0ea8606a953ff23bfb58 to your computer and use it in GitHub Desktop.
Save mingtsay/0ea8606a953ff23bfb58 to your computer and use it in GitHub Desktop.
Array.prototype.sayHi = function () {
var say = 'Hi, ' + this.join(', ') + '!';
window.alert(say);
}
var a = ['Bob', 'Alice', 'Emma'];
a.sayHi(); // this will alert: Hi, Bob, Alice, Emma!
for (var i in a) {
console.log(i, a.hasOwnProperty(i), a[i]);
}
/* console will show the following:
* "0" true "Bob"
* "1" true "Alice"
* "2" true "Emma"
* "sayHi" false function
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment