私は現在、JavaScriptとプロトタイピングについてより深く理解しようとしています。
関数を追加したかったのですdocumentが、prototypeで定義されていませんdocument。
このコード:
document.prototype.writeLine = function(text){
this.write(text);
this.write("<br />");
};
このエラーを生成します:
// In FireFox
TypeError: document.prototype is undefined
// In Chrome
Uncaught TypeError: Cannot set property 'writeLine' of undefined
documentオブジェクトを拡張して、似たようなものを呼び出せるようにするにはどうすればよいdocument.WriteLine('MyText')ですか?
これが私が使っているフィドルです。