function A() {
this.B = function() {
var bla;
};
}
A.B.prototype.foo = function() {console.log("Do whatever");};
I get this:
TypeError: Cannot read property ‘prototype’ of undefined
How to add a function to the prototype of B in this case?
There are a couple of mistakes in our code… here is how:
Your first issue was doing:
That’s not valid code, since you were calling method B and assing it a function, you had to reference the attribute.
Your other mistake, was not instantiating an “A” object, the function by itself can’t be used as an object, it can only be called. That’s why when you had:
You recieved that error message.
I hope that clears things up a bit for you, let me know if you have more doubts.