| Vogue Fatasy | |
|---|---|
| Title | Vogue Fantasy 20210419 |
| Date | 2021.04.19 |
| Description | U Neck Silk Crepe Dresses |
| Link | Instagram:@pixelart_zeki WebSite:Pixel Fantasy |
| Vogue Fatasy | |
|---|---|
| Title | Vogue Fantasy 20210419 |
| Date | 2021.04.19 |
| Description | U Neck Silk Crepe Dresses |
| Link | Instagram:@pixelart_zeki WebSite:Pixel Fantasy |
//只要是宣告過後的變數都不能刪除! 如:var、let、const、function,什麼意思呢? 舉例如下:
var thisVar = "I'm Var";
delete thisVar; //return false
let thisLet = "I'm Let";
delete thisLet; //return false
const thisConst = "I'm Const";
delete thisConst; //return false
function thisFunction(){
console.log("I'm Funciton");
}
delete thisFunction; //return false
//但是如果沒有宣告就可以刪除,舉例如下:
thisUndeclaredVar = "I'm UndeclaredVar";
delete thisUndeclaredVar; //return true
thisUndeclaredFunction = function(){
console.log("I'm UndeclaredFunciton");
}
delete thisUndeclaredFunction; //return true
//雖然物件本身不能刪除,但裡頭的屬性(變數)可以刪除,舉例如下:
var obj = {
a: 'a',
b: 'b',
c: 'c'
}
delete obj; //return false
delete obj.a; //return true
//那你妳可能會想問,我到底該如何知道所有的東西哪些能刪哪些不能刪呢?
//來吧,來下一個關鍵Object.getOwnPropertyDescriptor(物件,'屬性');的指令妳就明瞭了!
Object.getOwnPropertyDescriptor(window,'obj');
/* return:
{
configurable: false, //configurable中文翻成"可配置的",所以當true時代表可刪除,false代表不可刪除。
enumerable: true,
value: {a: "a", b: "b", c: "c"},
writable: true
}
*/
Object.getOwnPropertyDescriptor(window.obj,'a');
/* return:
{
configurable: true,
enumerable: true,
value: "a",
writable: true
}
*/
//更好的方法是使用Object.defineProperty來宣告configurable是否可以被刪除。且在嚴格模式(use stirct)下,不宣告的變數會出錯,例如:
'use strict';
thisUndeclaredVar = "I'm UndeclaredVar";
Uncaught ReferenceError: thisUndeclaredVar is not defined