引用类型作为参数传递的是地址

var per1 = new Person(“小明”,18);
console.log(per1.name+",年龄:"+per1.age);

var per2 = new Person("小花",12);
console.log(per2.name+",年龄:"+per2.age);

console.log(per1 instanceof Person);
console.log(per2 instanceof Person);

function Dog(name,age){
    this.name=name;
    this.age=age;
    this.sayHi = function () {
        console.log("你好,我叫"+this.name + "今年"+this.age);
    };
}
var dog1=new Dog("大黄",1);
dog1.sayHi();

console.log(dog1 instanceof Person);//false
console.log(dog1 instanceof Dog);//true

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44317018/article/details/88696423