码迷,mamicode.com
首页 > Web开发 > 详细

JS——delete

时间:2018-01-24 18:05:43      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:undefined   round   rip   log   def   type   script   this   prot   

1、对象属性删除

<script>
    function fun(){

        this.name = mm;

    }

    var obj = new fun();

    console.log(obj.name);//mm

    delete obj.name;

    console.log(obj.name); //undefined
</script>

2、变量删除

<script>
    var name = lily;
    delete name;
    console.log(name); //name is not defined
</script>

3、对象原型设置的属性无法删除

<script>
    function Person() {

    }
    Person.prototype.say=hello;
    var p=new Person();
    console.log(p.say);//hello
    delete p.say;
    console.log(p.say);//hello
</script>

 

JS——delete

标签:undefined   round   rip   log   def   type   script   this   prot   

原文地址:https://www.cnblogs.com/wuqiuxue/p/8342627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!