Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
// CREATE OBJECT
var obj = { "text" : "Hi" };
// TEST OBJECT KEY VALUE
alert( "OBJECT TEXT: "+ obj.text );     // Hi
// CREATE CUSTOM METHOD ( just like e.g. JS's .toUpperCase() method )
Object.prototype.addText = function(){ 
  return this+' there!';  
};
// USE CUSTOM .addText() METHOD
alert( "OBJECT TEXT+method: "+obj.text.addText() ); // Hi there! // wow, the method works!
for(var key in obj){
  alert( 'obj KEYS: '+ key ); // text // addText
}
// hmm... addText method as obj Key ???
// ok let's try with a new one...
var foobee = { "foo" : "bee" };
for(var key in foobee){
  alert( 'foobee KEYS: '+ key ); // foo // addText
}
// addText  ...again... but why?
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers