javascript - 基于对象与面向对象有什么区别?
阿神
阿神 2017-04-11 10:49:15
[JavaScript讨论组]
阿神
阿神

闭关修行中......

全部回复(2)
高洛峰

为什么不去百度搜!!!!!
http://zhidao.baidu.com/link?url=TqzKYxkCDOPkiEYNoO4ufmTO-7QOmMKydCzr36dANluNbNCzvZ9HSeHZlkIXpDhYoRWO_4-SHhTWe4aDeVfXua

PHP中文网

来这里问的好处是可以避免使用 Baidu,毕竟这里还是有人用 Google 的(逃)

Wikipedia: Object-based

In computer science, the term object-based has two different senses:

A somehow limited version of object-oriented programming, where one or more of the following restrictions applies: (a) There is no implicit inheritance, (b) there is no polymorphism, (c) only a very reduced subset of the available values are objects (typically the GUI components).

Prototype-based systems (that is, those based on "prototype" objects that are not instances of any class).

简要翻译下:

在计算机科学当中,基于对象一词有两种不同含义

  • 满足至少其一:没有明确的继承、没有多态、对象的使用只局限在很小的范围内

  • 基于原型而不是类的实例构建对象


补充一下:

在 ES2015 之前,Javascript 只能基于对象(参见 http://stackoverflow.com/a/6954346/3291805)

现在 ES2015 可以真正面向对象了(明确的继承)

class Base {
    foo(bar = '') {
        console.log('foo' + bar);
    }
}

class Example extends Base {
    constructor() {
        super();
        
        this.bar = 'bar';
    }
    foo() {
        super.foo(this.bar);
    }
}

new Base().foo(); // foo
new Example().foo(); // foobar
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号