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>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
  <p id="hello">Hello World</p>
</body>
</html>
 
if (document.getElementById('hello')) {
  document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript';
var A = function () {
    this.x = function () {
    alert('A');
    };
};
var B = function () { };
B.prototype.x = function () {
    alert('B');
};
var a = new A();
var b = new B();
a.x(); // displays A
b.x(); // displays B
A.x = function() {alert('C');};
a.x(); // displays A, but new instances of A will display C when x is called
var a2 = new A();
a2.x(); //displays A still
A.x(); //displays C when called as a singleton
  
B.prototype.x = function () {alert('D');};
b.x(); // displays D, because by changing prototype.x we have changed it for all
       // instances
b2 = new B();
b2.x();
  
}
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers