The Secrets of the ‘delete’ Operator in JavaScript
Posted by bitter-cognac@reddit | programming | View on Reddit | 19 comments
Posted by bitter-cognac@reddit | programming | View on Reddit | 19 comments
gmiller123456@reddit
I used the delete keyword as an example to show people their favorite "write once, run anywhere" Javascript framework wasn't really cross browser. In most browsers you could declare a variable named "delete", in IE6 it was a compile error. (Of course there were a lot of other cases too.)
birdbrainswagtrain@reddit
Why is this so heavily downvoted lol? Not a bad example even if it is dated. I'm sure you could find plenty of subtle inconsistencies right now if you just search through test262 results.
okcookie7@reddit
Right? I had the same reaction after reading the comment. Probably bots? I don't see how knowledge can be so offending
archerx@reddit
Most redditors here are teenagers and have no real world experience or wisdom. When you start seeing most posts and interactions here through that lens everything makes a lot more sense. It’s like dealing with the midwits from highschool again.
Also some users use bots to mass down vote people who contradict them. I have had posts stay at zero even though they were getting a lot of up votes, it was like for every up vote it received and immediate down vote was issued to balance it out. Fun times!
IBJON@reddit
Probably because using IE6 as baseline to show how bad JS is isn't really a fair demo.
It's been a long time since I've had to deal with IE6, but if memory serves, it never actually supported the ECMAScript standard - it used its own implementation called JScript. As a result, there were many features in ES that weren't supported and had to be patched using polyfills, and many of the features that did work, used an implementation that wasn't one-to-one with the implementation in other browsers.
Their point about JS not being a "write once, run anywhere" solution is valid, they just used a really bad comparison to demonstrate the point
gmiller123456@reddit
That does not change the fact that a framework claiming to support all modern browsers should, in fact support all modern browsers. I wouldn't expect it to today, but IE was very widely used regardless of whether it was a good idea for people to.
IBJON@reddit
IE6 hasn't been a "modern broswer" since 2008...
gmiller123456@reddit
I didn't claim it was.
IBJON@reddit
Your argument was that modern frameworks should support modern browsers while in you initial comment you used IE6 to demonstrate that the framework was no good.
There's virtually zero overlap in time where IE6 was considered a modern browser and the existence of production-ready JS frameworks (in fact I can't think of any that would have existed in 2008), so what exactly is your point?
gmiller123456@reddit
IE6's hey day was also the hey day for all of the "cross browser" frameworks, for obvious reasons. Everything in my post was in past tense, and the IE6 reference should have given you a reference as to when I was talking about. If you misunderstood, you have my apologies.
Cut_Mountain@reddit
Not that it actually changes anything to the overall discussion but Ext JS 2.0 was released around the end of 2007. Around that time I was working on an SPA that had to support IE6.
water_bottle_goggles@reddit
cool, but IE6 isn’t supported as much as chrome/edge/Firefox which delete probably works ok now
take a hike gramps
Nondv@reddit
angrily upvoted both comments
caseyfw@reddit
Me too… from my rocking chair.
oorza@reddit
And I remember people pointing to IE5 and Navigator as a reason to keep using
Who cares?
Somepotato@reddit
Delete does modify the original array. It also doesn't"skip" prototypes, it never interacts with them all because they're not part of the deleted object.
Really weird article
Doctor_McKay@reddit
Nitpicky semantical argument.
Delete doesn't resolve property names via inheritance. Saying that it "skips" the prototype is accurate enough for pretty much anyone to understand.
It's plain from context what the author meant with relation to deleting array elements. They obviously meant that you can use splice to modify the original array's length.
Somepotato@reddit
The mdn has a very clear definition of delete:
The delete operator removes a property from an object. If the property's value is an object and there are no more references to the object, the object held by that property is eventually released automatically.
Clear, concise and explains everything you need to know, the last part being particularly notable because the article stated it's impossible, but it's not impossible to use it to (eventually) clear memory.
If you're going to write a technical article, semantics are important. Yes the original array is modified. No, prototypes aren't affected because by definition it deleted a property from an object..not it's prototype.
Properties can exist on objects with a value of undefined. Delete works on these. That's an important thing to note that just setting to undefined can be insufficient. That is overlooked.
Even their other point - They also say properties are mounted on window. No, they're mounted on the global state, which in browsers is window, but other js runtimes it's not the case.
Don't write a technical article if your semantics aren't right. You'll just confuse people who expect what you write to be accurate verbatim.
Kafka_pubsub@reddit
TIL JS object property flags (I'm familiar with the equivalent in other languages, but never figured JS had it)