Hi,
Is there any way that I can define a destructor for an object in
JavaScript that will be called automatically when object is discarded?
<script type="text/javascript">
MyOBJ.prototype =new Object();
MyOBJ.prototype .constructor=My OBJ;
function MyOBJ()
{
alert('Construc tor!');
}
MyOBJ.prototype .destructor=fun ction()
{
alert('Destruct or!');
}
var my_obj=new MyOBJ(); //<-- will show 'Constructor!'
delete my_obj; //<-- will show 'Destructor!'
</script>
-thanks in advance, Eli
Is there any way that I can define a destructor for an object in
JavaScript that will be called automatically when object is discarded?
<script type="text/javascript">
MyOBJ.prototype =new Object();
MyOBJ.prototype .constructor=My OBJ;
function MyOBJ()
{
alert('Construc tor!');
}
MyOBJ.prototype .destructor=fun ction()
{
alert('Destruct or!');
}
var my_obj=new MyOBJ(); //<-- will show 'Constructor!'
delete my_obj; //<-- will show 'Destructor!'
</script>
-thanks in advance, Eli
Comment