标签:lin function new height com mil tps style 朋友
//构造函数创建对象
function student(name,age){ this.name = name; this.age = age; } function dog(name,age){ this.name = name; this.age = age; } var stud1 = new student("狗蛋",18); var dog1 = new dog("tom",1); console.log("我叫"+stud1.name+"今年"+stud1.age+"岁了,平时很调皮,我朋友说我很狗,但是我不是真的狗") console.log("我叫"+dog1.name+"今年"+dog1.age+"岁了,我是真的狗") console.log(stud1 instanceof student);//学生是学生类,狗是狗类,但他们都是object类 console.log(dog1 instanceof dog); console.log(stud1 instanceof dog); console.log(dog1 instanceof student); console.log(stud1 instanceof Object); console.log(dog1 instanceof Object);
运行结果:
标签:lin function new height com mil tps style 朋友
原文地址:https://www.cnblogs.com/hmy-666/p/14423772.html