zoukankan      html  css  js  c++  java
  • delete in javascript

    Key word delete.

    1. Delete global object.
    x = 42;         // creates the property x on the global object
    var y = 43;     // creates the property y on the global object, and marks it as non-configurable
    myobj = {
      h: 4,
      k: 5
    };
    
    // x is a property of the global object and can be deleted
    delete x;       // returns true
    
    // y is not configurable, so it cannot be deleted                
    delete y;       // returns false 
    
    // delete doesn't affect certain predefined properties
    delete Math.PI; // returns false 
    
    // user-defined properties can be deleted
    delete myobj.h; // returns true 
    
    // myobj is a property of the global object, not a variable,
    // so it can be deleted
    delete myobj;   // returns true
    
    function f() {
      var z = 44;
    
      // delete doesn't affect local variable names
      delete z;     // returns false
    }


    2. Function
    function Foo(){}
    Foo.prototype.bar = 42;
    var foo = new Foo();
    
    // returns true, but with no effect, 
    // since bar is an inherited property
    delete foo.bar;           
    
    // logs 42, property still inherited
    console.log(foo.bar);
    
    // deletes property on prototype
    delete Foo.prototype.bar; 
    
    // logs "undefined", property no longer inherited
    console.log(foo.bar);
    3. Array
    var trees = ["redwood","bay","cedar","oak","maple"];
    delete trees[3];
    if (3 in trees) {
        // this does not get executed
    }
    var trees = ["redwood","bay","cedar","oak","maple"];
    trees[3] = undefined;
    if (3 in trees) {
        // this gets executed
    }
  • 相关阅读:
    CAP概述与技术选型
    maven基础命令
    那就从头开始吧,哈哈。
    react 小细节
    二分查找法,折半查找原理
    心态很重要
    apache 软件基金会分发目录。
    jquery的基础知识复习()
    jquery的基础知识复习(基础选择器,属性选择器,层级选择器)
    CPP函数类型转换
  • 原文地址:https://www.cnblogs.com/RitaRichard/p/4323622.html
Copyright © 2011-2022 走看看