官术网_书友最值得收藏!

Blueprints versus finger-pointing

Let's start by looking at how typical object-oriented languages actually create objects.

We are going to talk about an object called myCar. The myCar object is our bits-and-bytes representation of an incredibly simplified real world car. It could have attributes like color and weight, and methods like drive and honk.

In a real application, myCar could be used to represent the car in a racing game  but we are going to completely ignore the context of this object, because we will talk about the nature and usage of this object in a more abstract way.

If you would want to use this myCar object in, say, Java, you need to define the blueprint of this specific object first  this is what Java and most other object-oriented languages call a class.

If you want to create the object myCar, you tell Java to build a new object after the specification that is laid out in the class Car.

The newly built object shares certain aspects with its blueprint. If you call the method honk on your object, like so:

 myCar.honk();

Then the Java VM will go to the class of myCar and look up which code it actually needs to execute, which is defined in the honk method of class Car.

Ok, nothing shockingly new here. Enter JavaScript.

主站蜘蛛池模板: 乐至县| 辽阳市| 海丰县| 芮城县| 临城县| 祁门县| 信阳市| 临泽县| 平南县| 临清市| 大石桥市| 千阳县| 黄石市| 瑞安市| 健康| 永新县| 澄城县| 灵丘县| 澄江县| 肇东市| 甘肃省| 古丈县| 台山市| 永德县| 鄂伦春自治旗| 色达县| 昌江| 盐城市| 合川市| 深水埗区| 伊金霍洛旗| 紫金县| 武鸣县| 铁岭县| 商都县| 富阳市| 旌德县| 景泰县| 福贡县| 阳城县| 黔江区|