zoukankan      html  css  js  c++  java
  • Javascript之delete运算符

    delete运算符是一个一元运算符,它将删除运算数所指定的对象的属性、数组元素或变量。如果删除操作成功,它将返回true,如果运算数不能被删除,它将返回false。注意删除属性、变量或数组元素不只是把它们的值设置为undefined。当输出一个属性后,该属性不再存在。并非所有的属性和变量都是可以删除的,某些内部的核心属性和客户端属性不能删除,用var语句生命的用户定义变量也不能被删除。如果delete使用的运算数是一个不存在的属性,它将返回true。

    var o = {x:1 , y:2};//Defined a variable;initialize to object

    detele o.x; //Delete one of the other properties;return true

    typeof o.x; //property does not exist;return "undefined"

    delete o.x; //Delete a nonexistent property;return true

    delete o; //Can't delete a declared variable;return false

    delete 1; //Can't delete an integer;return true

    x = 1; //Implicity declared a variable without var keyword

    delete x; //Can delete this kind of variable;return true

    x;  //Runtime error:x is not defined

    delete所能影响的只是属性值,并不能影响被这些属性引用的对象:

    var my = new Object(); //create an object named "my"

    my.hire = new Date(); //my.hire refers to a Date objct

    my.fire = my.hire; //my.fire refers to the same object

    delete my.hire; //hire property is deleted;return true

    docunment.write(my.fire);  //But my.fire still refers to the Date object

  • 相关阅读:
    Ⅲ:作业
    Ⅱ:python入门
    Auth模块
    django中间件
    Django的cookie以及session
    form组件
    Django Ajax
    Django模板层3和ajax初始
    聚合/分组 查询 事务
    Django ORM常用模块
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2524310.html
Copyright © 2011-2022 走看看