admin管理员组文章数量:1332377
Is there any chance to use prototype on a Form object, this is not working:
Form.prototype.myFunc=function()
{
alert('OK!');
}
On the other hand, String objects are extendable, for example:
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
Is there any chance to use prototype on a Form object, this is not working:
Form.prototype.myFunc=function()
{
alert('OK!');
}
On the other hand, String objects are extendable, for example:
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
Share
Improve this question
asked Jul 11, 2012 at 8:15
user1517081user1517081
9652 gold badges11 silver badges30 bronze badges
1
-
since there is no
Form
object - no, it doesn't work. – Otto Allmendinger Commented Jul 11, 2012 at 8:19
2 Answers
Reset to default 9If you means HTMLFormElement
, then it should be
HTMLFormElement.prototype.myFunc=function() {
alert('OK!');
};
There is no specification that requires DOM objects to implement any kind of inheritance, much less prototype inheritance. Having said that, many browsers do but it is not standardised or universally implemented.
You might like to read What’s wrong with extending the DOM.
In browsers that do implement a prototype inheritance scheme for DOM elements, you can try extending HTMLFormElement.prototype
using something like:
if (typeof HTMLFormElement == 'object' &&
typeof HTMLFormElement.prototype == 'object') {
// extend HTMLFormElement.prototype
}
Note however that the behaviour of host objects is entirely implementation dependant. The above may do anything, including throw errors.
本文标签: Extend Javascript Form object with prototypeStack Overflow
版权声明:本文标题:Extend Javascript Form object with prototype - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742294160a2448384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论