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
    }
  • 相关阅读:
    匈牙利游戏
    钓鱼
    路由选择
    借教室
    有趣的数
    广告印刷
    海战
    暑假周进度报告(一)
    在Oracle创建一个自己用的用户及角色
    下载,安装oracle数据库以及navicat连接数据库
  • 原文地址:https://www.cnblogs.com/RitaRichard/p/4323622.html
Copyright © 2011-2022 走看看