javascript - 基本构造函数对象帮助 - JS

标签 javascript object constructor

尝试学习 JS 中的对象,但在尝试让它工作时遇到了一些麻烦。它只是一个简单的对象构造函数,但似乎是我今天生活的祸根。不幸的是,我手边没有人可以帮助我。另外,如果有人知道带有现实生活中工作示例的优秀教程,而不是函数、循环等的工作原理,那么我真的很感激。

function car(model, doors, color, speed){

this.model = model;
this.doors = doors;
this.color = color;
this.speed = speed;

}

var powerCar = new car ("M3", "4 door", "phoenix", "220pmh");

console.log("This " + powerCar.model + "has " + powerCar.doors + "has a top speed of " powerCar.speed);

最佳答案

已修复。

问题出在这里:

console.log("This " + powerCar.model + "has " + powerCar.doors + "has a top speed of " powerCar.speed);

您需要在“speed of”和 powerCar.speed 之间添加一个 + 符号。

关于javascript - 基本构造函数对象帮助 - JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43625870/

相关文章:

c++ - 如何在设计实现层面避免内存泄漏

model - 如何在 Sencha 触摸模型中创建构造函数?

javascript - Google Visualization Table Chart - 更改列名称

javascript - 未通过 axios post 请求接收 Set-Cookie header

javascript - 将文本添加到 D3 donut chart 的中心

haskell fromInteger 具有多个数据构造函数

java - 从另一个类创建一个类的新实例

javascript - jQuery donut 插件 : Arrow doesn't show on print

javascript - 根据后面出现的所需项目数组对对象数组进行排序

JavaScript/jquery : get value from a combined key value array