novice_expert
asked on
Override function in javascript
How can I override some function for an object.
xmlHttpReqPost.onerror = function() is defined when the object is created.
I want to give new definition for onerror(),onload() likewise.
xmlHttpReqPost.onerror = function() is defined when the object is created.
I want to give new definition for onerror(),onload() likewise.
ASKER
basically i had overridden a function like onerror like this....now i want to give new definition of onerror i.e override old definition....
just re-assign it in your object, for example:
var obj = new MyClass();
obj.onerror = function_name;
// re-assign it
obj.onerror = function(){ };
Kind Regards
Bakr
var obj = new MyClass();
obj.onerror = function_name;
// re-assign it
obj.onerror = function(){ };
Kind Regards
Bakr
ASKER
it doesn't work....its calling the old definition?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
xmlHttpReqPost.onerror = function_name_here;
or you can declare your function while assigning
xmlHttpReqPost.onerror = function(){ alert('An error occured'); };
The followinf is an example for overriding the built in alert function:
<script type="text/javascript">
<!--
window.alert('This is the default alert');
function overrided(msg)
{
confirm(msg);
}
window.alert = overrided;
window.alert('This is the overrided one');
//-->
</script>
Kind Regards
Bakr