Question - How to associate functions with objects using JavaScript?
Answer -
Let's now create a custom "toString()" method for our movie object. We can embed the function directly in the object like this.
This produces
title: Narni director: Andrew Adamson
Or we can use a previously defined function and assign it to a variable. Note that the name of the function is not followed by parenthesis, otherwise it would just execute the function and stuff the returned value into the variable.
This produces
title: Aliens director: Cameron