Your B object wasn't initialised using the
new
keyword. When you initialise an object using the
new
keyword, the functions on the prototype will be applied to the resulting object. The correct way to define a class in JavaScript is:
A = function() {
};
A.prototype = {
fn: function() {
alert(1);
}
};
You then instantiate an object in this way;
var a = new A();
a.fn();
I recommend you read some of
Douglas Crockford's tutorials[
^].