I'm currently trying to get a better understanding of JavaScript and prototyping.
I wanted to add a function to the document
but prototype
is undefined on document
.
This code:
document.prototype.writeLine = function(text){
this.write(text);
this.write("<br />");
};
Generates this error:
// In FireFox
TypeError: document.prototype is undefined
// In Chrome
Uncaught TypeError: Cannot set property 'writeLine' of undefined
How can I extend the document
object to be able to call something similar to document.WriteLine('MyText')
?
Here is the Fiddle I'm working with.