Question: The below doesnt work and im struggling to work out why....

```
function CommentHandler() {

    var Text;
}

var myCommentHandler = new CommentHandler();

myCommentHandler.prototype.SayHello = function () {

    document.write('Hello World');

}

```

I get the error : 'myCommentHandler.prototype is undefined'

I just cant see why? I have declared a variable called myCommentHandler and copied in the object CommentHandler then Im trying to access the protoype of it and assign a function but I cant...Anyone know why?

Answer: 
The prototype belongs to the *class*, not the *instance*:

```
CommentHandler.prototype.MyFunction = ...

```

However you can also access the prototype via the instance's `constructor` property:

```
myObj.constructor.prototype.MyFunction = ...

```

This will of course add that function to *every* instance of your CommentHandler.

If instead you only wanted to add that function to that *one* instance, you'd do:

```
myObj.MyFunction = ...

```

Note that in none of these variants would it be possible for `MyFunction` to access your private variable `Text`.

This is the compromise forced by the prototype inheritance model - variables and methods must be public (e.g. `this.Text`) if they're to be accessed from outside, and in this case functions declared in the prototype are effectively "outside".

The alternative (using closure-scoped variables and methods) seems more natural to OO programmers, but makes inheritance much harder.
You have to use

```
CommentHandler.prototype.SayHello = function(){....}

```

You can find more about the prototype object in the following references  

<http://www.javascriptkit.com/javatutors/proto.shtml>  
<https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/prototype>  
<http://msdn.microsoft.com/en-us/magazine/cc163419.aspx>