Re-implement javascript delete keyword
As many of you are aware, the javascript delete keyword i开发者_如何学JAVAs a little tricky to use (see here). Is it possible to re-implement, or modify it? I have an object referenced multiple times and I want delete to remove all the references first. Like so:
var oj = new OrangeJuice();
var juice = oj;
var beverage = oj;
var allRightSunnyD = oj;
delete oj; //I want this to delete the actual object
I do not expect the garbage collector to find all of the references, lets say I know where the references are, i just want to re-implement delete to also get rid of juice, beverage and allRightSunnyD. I realize I could just implement a OrangeJuice.delete()
function, but I wanted to know if there was a way to do it right. Like if javascript would call an onDelete()
callback function prior to deleting objects.
- delete is a keyword, so it should not be altered even if you can
- delete is for deleting properties of objects, so you can not delete objects contained in single variables
look here how garbage collection in Javascript is explained: How does garbage collection work in JavaScript?
精彩评论