zoukankan      html  css  js  c++  java
  • js中的hasOwnProperty

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dogadd2</title>
        <script>
    
            function Dog(name, breed, weight){
                this.name = name;
                this.breed = breed;
                this.weight = weight;
            }
    
            Dog.prototype.species = "Canine";
            Dog.prototype.bark = function(){
                if (this.weight > 25){
                    console.log(this.name + " Woof");
                }
            };
    
            var fido = new Dog("fido", "mixed", 38);
            fido.bark();
    
    
    
            Dog.prototype.sitting = false;
            Dog.prototype.sit = function(){
                if (this.sitting){
                    console.log(this.name + " is already sitting");
                } else {
                    this.sitting = true;
                    console.log(this.name + " is start sitting");
                }
            };
            //hasOwnProperty,如果属性是在实例中定义的返回true,如果是在圆型定义返回false
    
    
            var barnaby = new Dog("Barnaby", "Basset Hound", 55);
            console.log(barnaby.hasOwnProperty("sitting"));
            barnaby.sit();
            console.log(barnaby.hasOwnProperty("sitting"));
    
            console.log(fido.hasOwnProperty("sitting"));
            fido.sit();
            console.log(fido.hasOwnProperty("sitting"));
            
    
        </script>
    </head>
    <body>
    
    </body>
    </html>
  • 相关阅读:
    Spring Data Rest如何暴露ID字段
    Windows空间清理2
    把爱好变成职业
    面对面的口头信息传递对人决策的影响力最大
    最好是更好的敌人
    文明主线
    钱的本质
    2019第42周日
    开源与商业化
    生涯四度
  • 原文地址:https://www.cnblogs.com/themost/p/9363995.html
Copyright © 2011-2022 走看看