• hasOwnProperty()函数


    hasOwnProperty()函数的返回值为Boolean类型。如果对象object具有名称为propertyName的属性,则返回true,否则返回false

    例子:

    function Site(){
        this.name = "CodePlayer";
        this.url = "http://www.365mini.com/";

        this.sayHello = function(){
            document.writeln("欢迎来到" + this.name);
        };
    }

    var obj = {
        engine: "PHP"
        ,sayHi: function(){
            document.writeln("欢迎访问" + this.url);
        }
    };
    // 使用对象obj覆盖Site本身的prototype属性
    Site.prototype = obj;

    var s =  new Site();
    document.writeln( s.hasOwnProperty("name") ); // true
    document.writeln( s.hasOwnProperty("sayHello") ); // true
    // 以下属性继承自原型链,因此为false
    document.writeln( s.hasOwnProperty("engine") ); // false
    document.writeln( s.hasOwnProperty("sayHi") ); // false
    document.writeln( s.hasOwnProperty("toString") ); // false

    // 想要查看对象(包括原型链)是否具备指定的属性,可以使用in操作符
    document.writeln( "engine" in s ); // true
    document.writeln( "sayHi" in s ); // true
    document.writeln( "toString" in s ); // true
  • 相关阅读:
    (转载)Bonding技术指南
    Linux配置虚拟地址
    VB6之写注册表
    Tomcat集群搭建
    VBS连接远程Oracle
    机器学习 目标函数,损失函数
    深度学习理解内容 初
    leetcode 39. Combination Sum
    leetcode 33. Search in Rotated Sorted Array
    leetcode 29. Divide Two Integers
  • 原文地址:https://www.cnblogs.com/moguzi12345/p/7518910.html
Copyright © 2020-2023  润新知