基于对象与面向对象有什么区别?
来这里问的好处是可以避免使用 Baidu,毕竟这里还是有人用 Google 的(逃)
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
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
为什么不去百度搜!!!!!
http://zhidao.baidu.com/link?url=TqzKYxkCDOPkiEYNoO4ufmTO-7QOmMKydCzr36dANluNbNCzvZ9HSeHZlkIXpDhYoRWO_4-SHhTWe4aDeVfXua