当前位置:网站首页>In depth understanding of JS delete
In depth understanding of JS delete
2022-06-22 04:56:00 【Iron helmet and anchor】
author : Kangax
Translation date : 2014 year 02 month 07 Japan
interpreter :
!!!!!!!! After the translation of the draft version , Another translation was found by inadvertent search , It is the same article original text , Better than my translation . justjavac, Madu It is an elder I respect very much , link as follows : javascript Medium delete
Although it cost 2 A few weeks , The progress is not ideal , But at least I know that I still have many gaps , It is worth it .
The lesson is that you must search for some keywords before doing translation .
explain : [ this paper Of original text We are talking about the first edition ...] In this paper , take property Unified translation into attributes , And will be attribute Translate into characteristics . such as eval.length, among length Namely eval function ( quote ) A property of , however length This attribute has some features , such as Not delete , Can not be modified, etc .
A few weeks ago , I have the honor of reading stonov (Stoyan Stefanov) Of
Object-Oriented Javascript A Book .( The book got a very high rating on Amazon ,12 Five star evaluation . Translation notes : Amazon is the most abstemious online bookstore , The comments are basically true and reliable ), So I'm curious , I want to see what are the praiseworthy dry goods . I started from functions From the beginning of the first chapter , The writing is very smooth and free ; The example is very useful , The structure is particularly clean 、 Refreshing . In my opinion, beginners can also get started quickly and master the main points . But soon I came across a small pit —— About deleting function An interesting misunderstanding . Of course, there are other small mistakes ( Such as the difference between function declaration and function expression ), But in this paper The discussion started in .
The book says ”
function Variables considered normal - Can be copied to another variable , It can even be deleted .” Behind this explanation , There is an example :
>>> var sum = function(a, b) {return a + b;}
>>> var add = sum;
>>> delete sum
true
>>> typeof sum;
"undefined"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
Ignore missing semicolons , Can you find anything wrong with this code ? Of course , The problem is , Delete sum Variables should not succeed ; delete Statement should not return true , and typeof sum Nor should it return “undefined”. because
stay Javascript It is impossible to delete variables in . At least not in this way .
So why does this example go wrong ? This is a mistake ? joke ? Should not be . The whole code snippet is actually
Firebug Console Output , Stoyan It must have been tested quickly . as a result of Firebug It seems that some different deletion rules have been adopted . So it is Firebug Lead to Stoyan Make a mistake here ! But what the hell is going on ?
Answer that question , We need to understand that in Javascript in delete How operators work : What can be deleted , What cannot be deleted and why . Now I will try to explain the reasons in detail . We will find out Firebug “ weird ” And realize that not everything is weird , We will delve into when declaring variables ,functions, Specify properties and delete them What happened behind the scenes ; We will list the promises of browsers and some of the most notorious bug; We will also discuss the Fifth Edition ECMAScript The strict model of , And how it changes delete The behavior of the operator .
stay this paper in Javascript and ECMAScript All means ECMAScript( Unless specifically stated as Mozilla Of Javascript Realization ).
It is as expected , On the Internet about delete The explanation is quite rare .
MDC The article Probably the most comprehensive resource , Unfortunately, some interesting details were missed ; Strangely enough , One of these forgotten things is Firebug The reason for the complex behavior of . and
MSDN Reference manual Almost useless .
1. The basic principle
We can delete an attribute of an object :
var o = { x: 1 };
delete o.x; // true
o.x; // undefined
- 1.
- 2.
- 3.
But you cannot delete variables , For example, it is declared in the following way :
var x = 1;
delete x; // false
x; // 1
- 1.
- 2.
- 3.
Nor can you delete functions , As defined below :
function x(){}
delete x; // false
typeof x; // "function"
- 1.
- 2.
- 3.
Be careful If
If an attribute cannot be deleted , delete The operation will return to false.
To understand that , We first need to understand variable instantiation and property Attributes and other concepts —— Unfortunately in Javascript These things are rarely covered in the books of . I will briefly introduce these in the next few paragraphs . These concepts are not difficult to understand ! If you don't care
Why? JavaScript The way it works , Please skip this chapter .
1.1 Classification of executable code
stay ECMAScript There is 3 Types of executable code : Global code , function code , as well as Eval Code .
These types are self describing , Here is a brief overview :
- When a text source Be treated as a program , It executes globally , Considered global code (Global code). In the browser environment , SCRIPT The content of an element is usually parsed into a program , So it is equivalent to global code .
- Something that is executed directly within a function , Obviously , It is considered a piece of function code (Function code). In the browser , Contents of event attributes ( for example <p onclick = "…" > ) It is usually parsed and considered a piece of functional code .
- Last , Built in eval The text in the function is parsed as Eval code. We will soon see why this type is special .
1.2 Execution context
When ECMAScript Code execution , It is always in a specific execution context . The execution context is an abstract existence , It helps to understand scope and Variable instance How it works . For three types of executable code , Each has an execution context . When a function executes , Can be said to be controlled to enter Function Code execution context ; When the global code executes , Enter the execution context of the global code wait .
As you can see , The execution context logically forms a stack . The first is the global code and its execution context ; The global code can call a function , There is a function's own execution context , This function can call another function , Etc., etc. . Even if a function recursively calls itself , Each call will also enter a new execution context .
1.3 Activation object /Variable object
Each execution context has a named
Variable object ( Active object ?) Objects associated with . Similar to the execution context ,Variable Object is also an abstract existence , A mechanism for describing variable instantiation . Now? , What's interesting is that , Variables and functions declared in a source text are actually
Add as this Variable object Object properties (properties).
When entering the global code execution context , Global object (Global object, As in the browser window) Be regarded as its Variable object object . This is why variables or functions declared in the global scope
Become an attribute of the global object Why :
/* When in the global scope , `this` It points to global object */
var GLOBAL_OBJECT = this;
var foo = 1;
GLOBAL_OBJECT.foo; // 1
foo === GLOBAL_OBJECT.foo; // true
function bar(){}
typeof GLOBAL_OBJECT.bar; // "function"
GLOBAL_OBJECT.bar === bar; // true
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
OK, Global variables become properties of global objects , But local variables ( Declare inside a function ) How to deal with it ? It's actually very similar : They become Variable Object properties (properties). The only difference is , When in function code ,Variable Object is not a global object , But one called
Activation object The object of . Each time you enter the execution context of a function, a Activation object object .
Not only the variables and functions declared inside the function will become Activation object Object properties ; And every parameter of the function ( Corresponding to the corresponding parameter name )、 And a special Arguments object ( be known as arguments ) It will be Activation object Object properties . Be careful , Activation Objects are just an internal mechanism , Programs can never really visit ( quote ) To this object .
(function(foo){
var bar = 2;
function baz(){}
/*
In terms of abstract and virtual ,
Proprietary `arguments` Object becomes the corresponding function Activation An attribute of an object (property):
ACTIVATION_OBJECT.arguments; // Arguments object
... Of course , Parameters `foo` It's the same thing :
ACTIVATION_OBJECT.foo; // 1
... meanwhile , local variable `bar` The same is true of :
ACTIVATION_OBJECT.bar; // 2
... The same is true for defined local functions :
typeof ACTIVATION_OBJECT.baz; // "function"
*/
})(1);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
Last , stay Eval Variables declared in code are created as
Call context Variable object Object properties . in short ,Eval Where the code is called , Internal variables are equivalent to where they are declared :
var GLOBAL_OBJECT = this;
/* here eval Internal `foo` Be created for Call context Variable Object properties ,
Here the context object is the global object Global object */
eval('var foo = 1;');
GLOBAL_OBJECT.foo; // 1
(function(){
/* `bar` Be created for Call context Variable object An attribute of an object ,
here Variable object Objects are contained function One of the Activation object */
eval('var bar = 1;');
/*
From a virtual abstract point of view ,
ACTIVATION_OBJECT.bar; // 1
*/
})();
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
1.4 Property attribute
Basically, I have finished what I should say . It is now clear how variables are handled ( They became properties attribute ), The only remaining concept to understand is property attribute . Every property Can have the following 0 To multiple features ——
ReadOnly,
DontEnum,
DontDelete as well as
Internal. You can think of them as
Sign a —— every last property May or may not exist in attribute . For the following discussion , We are only right DontDelete Interested in .
When declared variables and functions become Variable object Object's properties —— May be Activation object object ( about Function code Come on ), Or global objects ( For global code ), these properties When created
Given to DontDelete attribute attribute . However , Any explicit ( Or implicit ) Specify property Created by the assignment of an attribute property Attribute is
No, DontDelete attribute . That's why we can delete some properties attribute , Other essential reasons that cannot be deleted :
var GLOBAL_OBJECT = this;
/* `foo` yes Global object One of the property.
Is created through variable declarations , So we have DontDelete sign .
This is why it cannot be deleted . */
var foo = 1;
delete foo; // false
typeof foo; // "number"
/* `bar` yes Global object One of the property.
It's through function Declaration created , So we have DontDelete sign .
This is why it cannot be deleted . */
function bar(){}
delete bar; // false
typeof bar; // "function"
/* `baz` The same is Global object One of the property.
But by property Created by assignment ,However, So there is no DontDelete sign .
This is why it can be deleted . */
GLOBAL_OBJECT.baz = 'blah';
delete GLOBAL_OBJECT.baz; // true
typeof GLOBAL_OBJECT.baz; // "undefined"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
1.5 Built in and non removable
DontDelete refer to : stay property A special on attribute, Used to control whether this... Can be deleted property. Be careful , The properties of some built-in objects are specified as DontDelete, So it cannot be deleted . special arguments Variable ( perhaps , As we just introduced , Activation Object properties etc. ) Have DontDelete sign . all function Example of length attribute ( Number of formal parameters ) Also has the DontDelete sign :
(function(){
/* Can't delete `arguments`, Because it owns DontDelete */
delete arguments; // false
typeof arguments; // "object"
/* Can't delete function Of `length`; it also has DontDelete */
function f(){}
delete f.length; // false
typeof f.length; // "number"
})();
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
Corresponding to function Parametric properties It is also endowed with DontDelete sign , So it cannot be deleted :
(function(foo, bar){
delete foo; // false
foo; // 1
delete bar; // false
bar; // 'blah'
})(1, 'blah');
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
1.6 Undeclared assignment
you
Maybe remember , Undeclared assignment ( No, var Definition )
A property will be created on the global object . Unless an attribute with the same name has been found on the scope chain before the global scope object is found . Now we know property Assignment and variable declaration The difference between —— The latter is set DontDelete sign , The previous one is not set —— Why?
Undeclared assignment Created property It's erasable Now it's obvious ( No settings DontDelete sign ):
var GLOBAL_OBJECT = this;
/* By variable declaration And create a global property; Have DontDelete sign */
var foo = 1;
/* Created by undeclared assignment global property; No, DontDelete sign */
bar = 2;
delete foo; // false
typeof foo; // "number"
delete bar; // true
typeof bar; // "undefined"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
Be careful , attributes yes
stay property Determined during creation ( Even if nothing is set ). Future assignments will not modify existing property Of attributes. It is important to understand the difference .
/* `foo` is created as a property with DontDelete */
function foo(){}
/* Later assignments do not modify attributes. DontDelete is still there! */
foo = 1;
delete foo; // false
typeof foo; // "number"
/* But assigning to a property that doesn't exist,
creates that property with empty attributes ( So there is no DontDelete sign ) */
this.bar = 1;
delete bar; // true
typeof bar; // "undefined"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
2. Firebug Perplexity of
that Firebug What on earth is going on in ? Why is it console Variables declared in can be deleted , Contrary to what we just learned ? Um. , As I said before ,Eval Code has a special behavior when it becomes a variable declaration .
stay Eval The variables declared in the code actually do not DontDelete logo :
eval('var foo = 1;');
foo; // 1
delete foo; // true
typeof foo; // "undefined"
- 1.
- 2.
- 3.
- 4.
Again , When calling... Inside a function Eval Code :
(function(){
eval('var foo = 1;');
foo; // 1
delete foo; // true
typeof foo; // "undefined"
})();
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
This is it. Firebug The point of abnormal behavior . It seems that all the text in the console
Be treated as Eval Code Parsing and execution , Not global code or function code . obviously , Any declared variable will eventually
No, DontDelete sign , So it can be easily deleted . Please pay attention to General global code and Firebug These differences in the console .
2.1 adopt eval Delete variables
This is a eval An interesting act , add ECMAScript Another aspect of can technically allow us to delete non-deletable Of properties. In the same execution context , A declaration of a function overrides a variable with the same name ( The principle is context in , Variable declarations are advanced to the entire context front ,function The statement was also advanced , But it should be function The statement was After mentioning variable declarations , therefore ...):
function x(){ }
var x; // Only declare
typeof x; // "function"
function a(){ }
var a = 6; // Statement + assignment
typeof a; // "number"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
Be careful , Function declarations take precedence and override same-named( Homonymous ) Variable ( perhaps , let me put it another way ,Variable Object property ). This is because function Declaration after variable declaration Instantiation , And allow them to be overwritten . Function declarations not only replace property The previous value of , It also replaces the property Characteristics of (attributes). If we pass eval Statement function, This function should also replace this with its own property Of attributes . Because in eval Created by variables declared in properties No, DontDelete sign , Instantiating this new function should essentially
remove property The existing DontDelete attribute , In order to make remove property Can be deleted ( Of course , Make sure it also points to the newly created function ).
var x = 1;
/* Can't delete , `x` has DontDelete */
delete x; // false
typeof x; // "number"
eval('function x(){}');
/* `x` property Now point to function, And there's no DontDelete sign */
typeof x; // "function"
delete x; // It should be `true`
typeof x; // It should be "undefined"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
Unfortunately , In all the implementation environments I tested , This kind of deception will not work . I may have said something wrong here , Or this behavior is too obscure , So that the implementer doesn't go Focus on .
3. Browser compatibility
It is useful to understand how things work , But it is more important to understand the actual operating environment . Browser processing Variable / attribute Of establish / Delete Do you follow the standards ? in the majority of cases , That's true .
I wrote
A simple test script To test delete Operator on global code ,Function Code and Eval The operation of the code Compliance with specifications . Test script check - delete The return value of the operator , And whether the attribute should be deleted when it should be deleted . delete The return value of is less important than its actual result . It's not very important if the deletion returns true, instead of false, But have DontDelete Characteristic properties It's important that it hasn't been deleted , vice versa .
The compatibility of modern browsers is usually very good . In addition to me
I mentioned the special eval , The following browsers completely passed the test suite :Opera 7.54 +,Firefox 1.0 +,Safari 3.1.2 +,Chrome 4 +.
Safari 2.x and 3.0.4 In the delete function arguments Sometimes there are problems ; these properties It seems that... Is not given when it is created DontDelete characteristic , So it can be deleted . Safari 2.x There are even more problems —— Delete non references ( for example delete 1;) Will throw an error ; function The declaration will create Removable properties ( But it's strange ,variable Declarations cannot be deleted ); And in the eval in variable The statement becomes non-deletable( But this is not the case with function declarations ).
Be similar to Safari,Konqueror(3.5, instead of 4.3) When deleting non references ( for example delete 1;) Will throw an error , It also incorrectly allows functions to be deleted arguments.
3.1 Gecko Engine DontDelete defects
Gecko 1.8.x Browser ,Firefox 2.x,Camino 1.x,Seamonkey 1.x, wait —— Show an interesting bug, When you explicitly give a property After the assignment , Will remove its DontDelete characteristic , Even if it's time to property Is declared through variables or functions And created :
function foo(){}
delete foo; // false ( In line with expectations )
typeof foo; // "function" ( In line with expectations )
/* Now show me a property assignment */
this.foo = 1; // Mistakenly cleared DontDelete characteristic
delete foo; // true
typeof foo; // "undefined"
/* Pay attention when implicitly giving property Assignment does not occur */
function bar(){}
bar = 1;
delete bar; // false
typeof bar; // "number" ( The assignment operation replaces property)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
It's amazing ,Internet Explorer 5.5 - 8 Completely passed the test of the test suite , In addition to removing non references ( for example detele 1;) Will throw an error ( Like in an older Safari In the same ). But in
IE There are actually more serious bugs, these bug Will not show up immediately . These defects are related to global objects .
4. IE Of Bugs
The whole article only has Internet Explorer There is BUG Do you ? How unexpected !
stay IE( At least IE6 - IE8), The following expression will throw an error ( stay Global code When performed in the ):
this.x = 1;
delete x; // TypeError: Object doesn't support this action
- 1.
- 2.
The same goes for the following , But a different exception was thrown , It's very interesting :
var x = 1;
delete this.x; // TypeError: Cannot delete 'this.x'
- 1.
- 2.
stay IE in , Variables declared in the global code do not seem to be created as attributes on the global object . Create attributes by assignment ( this.x = 1; ), And then through delete x; Deleting it will throw an error . Create attributes by declaration ( var x = 1;), And then use delete this.x; Deleting it throws another error .
But that's not all . Attributes created by explicit assignment are deleted
Always throw errors . Not only is there an error here , And the created attribute seems to have been set DontDelete sign , Of course, this should not be :
this.x = 1;
delete this.x; // TypeError: Object doesn't support this action
typeof x; // "number" (still exists, wasn't deleted as it should have been!)
delete x; // TypeError: Object doesn't support this action
typeof x; // "number" (wasn't deleted again)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
Now? , Contrary to people's expectations , Undeclared assignment ( You should create a... On the global object property ) stay
IE Create a delectable properties:
x = 1;
delete x; // true
typeof x; // "undefined"
- 1.
- 2.
- 3.
But if you want to pass through the global code this Reference to delete this property ( delete this.x), Then a familiar mistake will pop up :
x = 1;
delete this.x; // TypeError: Cannot delete 'this.x'
- 1.
- 2.
If we reason about this behavior , You will find that in the global code execution delete this.x; Will never succeed . When property Is created by explicit assignment ( this.x = 1;), delete An error will be thrown ; When property Is created by undeclared assignment ( x = 1) Or create by variable declaration ( var x = 1), delete Will throw another error .
To put it another way , delete x; Only when property The error is thrown only when it is created by explicit assignment ——this.x = 1;. If property Is created through variable declarations (var x = 1;), Deletion simply never takes place , also delete Return correctly to false. If property Is created by undeclared assignment (x = 1), Delete runs as expected .
I am a stay 9 Month feedback on this issue Of , Garrett Smith It is suggested that IE in “The global variable object Be implemented as a JScript object , also global object By host To achieve ".Garrett Suggestions for reference Eric Lippert The blog of . We can confirm this theory by performing some tests . Be careful , this and window Point to the same object ( We can use === Operator to test ), however Variable object ( The one that declared the function ) And this Different references .
/* in Global code */
function getBase(){ return this; }
getBase() === this.getBase(); // false
this.getBase() === this.getBase(); // true
window.getBase() === this.getBase(); // true
window.getBase() === getBase(); // false
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
5. misunderstand
A beautiful understanding of things and how they work and how they work cannot be underestimated . I see some things on the Internet that I don't really understand
delete Some misunderstandings caused by operation . for example , This is Stackoverflow An answer to ( An astonishingly high rating ), Confidently explain “ When the deleted target is not an object property when ,delete There should be no operation ”. Now we understand
delete The core of behavior , It is clear that , The answer is rather inaccurate . delete Do not distinguish between variables and attributes ( in fact , about delete Come on , These are all references ), And only care about DontDelete characteristic (property To exist ).
It's also interesting to see misunderstandings bounce off each other , In the same thread Someone in suggested deleting variables first ( Of course, it won't work , Except in
eval In a statement ), Then another person offered A correction of errors How to delete variables in global code instead of Function In the code .
Please use with care Web Yes Javascript The explanation of , In an ideal situation , We should seek to understand the core of the problem ;)
6. 'delete' And host object ( Host object ?)
Yes delete One of the algorithms of is like this :
- If the operand is not a reference , return true
- If the object doesn't have this name Of direct property, return true( As we know now , The object can be Activation Object or Global object )
- If property There is , But with DontDelete characteristic , return false
- Other situations , Delete property And back to true
However ,
delete Operator and host The behavior of an object can be quite unpredictable . In fact, nothing went wrong : ( The specification allows ) host Object pair operations Implement any form of behavior , Such as read ( Inside [[Get]] Method ), write ( Inside [[Put]] Method ) or delete ( Inside [[Delete ]] Method ), And other operations . For customization [[Delete]] Your behavior is host The reason why the object is so confused .
We've seen some IE Strange , Delete certain objects ( This is obviously implemented as host object ) Will throw an error . Some version of Firefox Trying to delete window.location Will also throw . When it comes to host Object time , You can't believe delete The return value of , Look at the Firefox What's going to happen in :
/* "alert" yes `window` One of the direct property
( If we accept `hasOwnProperty` Words ) */
window.hasOwnProperty('alert'); // true
delete window.alert; // true
typeof window.alert; // "function"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
Delete window.alert return true , Even for this property There is no reason for this . It resolves to a reference ( So you can't go back in the first part true). This is a window One of the direct property( So the second step cannot be returned true;). delete Operation return true The only way Is the fourth step to the algorithm , And actually deleted an attribute . Yes , ad locum property Has never been deleted .
The moral of this story is
Never trust host object .
As one bonus, Here is IE in delete A strange behavior case :
var element = document.createElement('div')
delete element.onclick; // throws "Object doesn't support this action"
document.body.x = 1;
delete document.body.x; // throws "Object doesn't support this action"
// in IE8
delete XMLHttpRequest.prototype.open; // throws "Object doesn't support this action"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
7. EcmaScript5 Strict mode
that
ECMAScript5 What does the strict model of ? Introduced some limitations . When using delete Operator to delete Variable , Function parameter or function identifier Direct reference to , It will be thrown out. SyntaxError Grammar mistakes . Besides , If property Inside [[Configurable]]== false when , Will throw out TypeError:
(function(foo){
"use strict"; // Use... In this function strict mode
var bar;
function baz(){}
delete foo; // SyntaxError (when deleting argument)
delete bar; // SyntaxError (when deleting variable)
delete baz; // SyntaxError (when deleting variable created with function declaration)
/* Function instance `length` Attributes have { [[Configurable]] : false } */
delete (function(){}).length; // TypeError
})();
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
Besides , Delete undeclared variables ( Or to put it another way , Unresolved references ) Syntax errors will also be thrown :
"use strict";
delete i_dont_exist; // SyntaxError
- 1.
- 2.
This is somewhat similar to the behavior of undeclared assignments in strict mode ( Except for throwing ReferenceError instead of SyntaxError outside ):
"use strict";
i_dont_exist = 1; // ReferenceError
- 1.
- 2.
You now understand , The meaning of all these restrictions , To delete variables , Function declarations and arguments What causes so much confusion .
In strict mode , Will not silently ignore delete , It needs more
Radical and The basis of (descriptive) measures .
8. Summary
This article is very long , So I'm not going to talk about things like using delete To remove array items (array items) And what it means . You can refer to MOZILLA
about delete Detailed description of ( Or search and experiment by yourself ).
Here is about Javascript A short summary of the deletion mechanism in :
- Both variable and function declarations are Activation or Global Object's properties.
- Properties Have attributes characteristic , One of them is DontDelete, decision property Can it be deleted .
- In global and Function Variables and functions declared in code , Created properties Always endowed with DontDelete sign .
- function arguments It's also Activation Object's properties , And at the time of creation DontDelete sign .
- stay Eval The variables and functions declared in the code are creating properties Not at the time DontDelete sign .
- Newly designated properties When creating, the flag bit is empty Of ( So there was no DontDelete sign ).
- Host The object decides whether it is allowed to be deleted .
If you want to know more , see also :
ECMA-262 standard _en.pdf
I hope you enjoy this overview and learn something new . As always, any questions are welcome , Recommendations and amendments .
边栏推荐
- ln n, n^k , a^n, n!, n^n的极限问题
- go学习(二、内建容器)
- 重构思维系列2-函数及变量
- 系统整理|这个模型开发前的重要步骤有多少童鞋忘记细心做好(实操)
- torch DDP Training
- [fault diagnosis] the picture cut code cannot be cut out, slide read_ Region does not run, but the program does not report an error
- Redis 主从复制
- Common knowledge arrangement of numpy database
- 《数据库原理》期末考试题
- Lightweight CNN design skills
猜你喜欢

NLP 的 不可能三角?

网页设计与制作期末大作业报告——小众音乐网站

"O & M youxiaodeng" active directory batch modification user

The Impossible Triangle of NLP?

并发编程——线程池

Get the specified row content in Oracle rownum and row_ number()
![[fault diagnosis] CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace B](/img/f3/86bc79d7b2fb0a7f5ab77d5bbbeb18.png)
[fault diagnosis] CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace B

Lua exports as an external link library and uses

Gavin's perception of transformer live class - NLU and policies data decryption, source code analysis and practice of insurance BOT in the insurance industry of Rasa dialogue robot project (57)

JUC - 线程中断与线程等待、唤醒(LockSupport)
随机推荐
uwsgi-invalid-request-block-size invalid request block size: 21327 (max 4096)... Skip solution
第6章无穷级数_傅立叶级数
NFC authentication makes the ultimate KYC experience
mysql常用sql
Code example of map and entity class Interoperation
The best time to climb a ladder & sell shares (notes of the runner)
go学习(二、内建容器)
mongo模糊查詢,帶有特殊字符需要轉義,再去查詢
Why does golang not recommend this/self/me/that/_ this
Learning signal integrity from scratch -- 7-si analysis and simulation
Leetcode -- the kth largest node of the binary search tree (traversal by means of middle order)
【sdx12】使用QCMAP_CLI启动WiFi操作说明
Solutions to MySQL 8.0 public key retrieval is not allowed errors
Ora-15063: ASM discovered an insufficient number of disks for diskgroup
网页设计与制作期末大作业报告——大学生线上花店
Reasons and Countermeasures for ThinkPHP's session being unable to obtain session in different ways in the same controller
C # WinForm listview control has no scroll bar and has written an extension control by itself
Slurm tutorial
Remote Dictionary Server(Redis)——基于 KV 结构的作为 Cache 使用的 NoSQL 数据库管理系统
Reading notes on how MySQL works [updating]