【发布时间】:2021-05-13 14:37:19
【问题描述】:
var myHonda = {
color: 'red',
wheels: 4,
engine: {
cylinders: 4,
size: 2.2
},
distance: 40,
time: 1,
speed: function(distance, time) {
distance = this.distance;
time = this.time;
console.log(distance / time);
// console.log(`Current speed is ${this.distance * this.time} `);
}
};
var myHonda2 = {
color: 'red',
wheels: 4,
engine: {
cylinders: 4,
size: 2.2
},
distance: 20,
time: 2,
speed: function(distance, time) {
distance = this.distance;
time = this.time;
console.log(distance / time + "kmph");
}
};
let displaySpeed = function(myObject) {
console.log(`Speed of Car is ${myObject.speed}`);
}
displaySpeed(myHonda);
displaySpeed(myHonda2);
【问题讨论】:
-
所以你写了一个标题并发布了一些代码,我没有看到任何问题或想要的结果。或任何解释。请访问stackoverflow.com/help/how-to-ask和minimal reproducible example是什么
标签: javascript function object