C
codefragment
Noddy question for someone but...
I can use prototype to add a method to a class, if an object is
created locally it works but I can't add methods to objects already
existing in the dom?
Sure someone somewhere has written about this but the nature of the
keywords prototype and
class make it difficult to search for
thanks for any help
<body>
<form>
<input id=theButton type=button onclick="func(this)" />
<script>
Object.prototype.bob = function()
{
alert('bob')
}
function func(elem)
{
var theButton = document.getElementById('theButton');
var obj = new Object();
obj.bob(); // works
theButton.bob(); // doesn't work
}
</script>
</form>
</body>
I can use prototype to add a method to a class, if an object is
created locally it works but I can't add methods to objects already
existing in the dom?
Sure someone somewhere has written about this but the nature of the
keywords prototype and
class make it difficult to search for
thanks for any help
<body>
<form>
<input id=theButton type=button onclick="func(this)" />
<script>
Object.prototype.bob = function()
{
alert('bob')
}
function func(elem)
{
var theButton = document.getElementById('theButton');
var obj = new Object();
obj.bob(); // works
theButton.bob(); // doesn't work
}
</script>
</form>
</body>