码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 面向对象编程

时间:2017-04-18 19:07:32      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:object   创建   logs   height   test   robot   javascrip   creat   htm   

// 原型对象:
var Student = {
    name: ‘Robot‘,
    height: 1.2,
    run: function () {
        console.log(this.name + ‘ is running...‘);
    }
};

function createStudent(name) {
    // 基于Student原型创建一个新对象:
    var s = Object.create(Student);
    // 初始化新对象:
    s.name = name;
    return s;
}

var xiaoming = createStudent(‘小明‘);
xiaoming.run(); // 小明 is running...
xiaoming.__proto__ === Student; // true

  

 

JavaScript 面向对象编程

标签:object   创建   logs   height   test   robot   javascrip   creat   htm   

原文地址:http://www.cnblogs.com/chenjf/p/6729205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!