首页 > 代码库 > js的面向对象编程

js的面向对象编程

<html>
<meta charset="UTF-8" />
<head>
<script>
var Student = {
name:"Root",
heighe:1.2,
run:function() {
console.log(this.name+‘ is running...‘);
}
};

function createStudent(name) {
var s = Object.create(Student);
//初始化对象
s.name = name;
return s;
}

window.onload = function () {
var xiaoming = createStudent("小明");
xiaoming.run();
}
</script>
</head>
<body></body>
</html>

 

js的面向对象编程