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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742294160a4416776.html
评论列表(0条)