67 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The semantics of the ``++delete++`` operator are a bit tricky, and it can only be reliably used to remove properties from objects. Pass anything else to it, and you may or may not get the desired result.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var x = 1;
delete x; // Noncompliant
function foo(){
..
}
delete foo; // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var obj = {
x:1,
foo: function(){
...
}
};
delete obj.x;
delete obj.foo;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this "delete" operator or pass an object property to it.
=== Highlighting
* Primary: entire ``++delete++`` expression
'''
== Comments And Links
(visible only on this page)
=== on 4 Jun 2015, 12:13:03 Elena Vilchik wrote:
\[~ann.campbell.2] Assign to you for validation and completion (labels, SQALE). CC [~linda.martin]
=== on 4 Jun 2015, 14:10:16 Ann Campbell wrote:
\[~elena.vilchik] I've updated the description based on \https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete, which shows that _sometimes_ ``++delete++`` does work on things that might be thought of as variables (even though they're really properties of the global object.)
Let me know if it's not okay
endif::env-github,rspecator-view[]