extend - Re-implement javascript delete keyword - Stack Overflow

As many of you are aware, the javascript delete keyword is a little tricky to use (see here). Is it pos

As many of you are aware, the javascript delete keyword is 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.

As many of you are aware, the javascript delete keyword is 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.

Share Improve this question edited Aug 8, 2015 at 10:59 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 7, 2011 at 14:38 pukpuk 16.8k31 gold badges126 silver badges206 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7
  1. delete is a keyword, so it should not be altered even if you can
  2. 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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745317669a4622291.html

相关推荐

  • extend - Re-implement javascript delete keyword - Stack Overflow

    As many of you are aware, the javascript delete keyword is a little tricky to use (see here). Is it pos

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信