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>

 

posted @ 2016-11-27 12:14  码农之路2015  阅读(74)  评论(0)    收藏  举报