我试图找出:如何log
对象原型中的实际对象名称。
Object.prototype.contentAndname = function() {
console.log()//what should be getting logged is bikes
}
transportation = {
automobile: {
cars: {
nissan: ["Altima", "Leaf"],
tesla: ["Model S", "Model X"],
},
trucks: {
ford: ["Super Duty", "F-150"],
chevy: ["Silverado", "Colorado"],
}
},
bikes: {
cheap: ['homemade'],
luxury: ['gucci']
},
legs: {
human: [],
dogs: [],
cats: []
}
}
transportation.bikes.contentAndname()
Object.prototype.contentAndname = function() {
// Code that figures out that the object being pass through is called bikes.
console.log('bikes')//what should be getting logged is bikes
}
transportation = {
automobile: {
cars: {
nissan: ["Altima", "Leaf"],
tesla: ["Model S", "Model X"],
},
trucks: {
ford: ["Super Duty", "F-150"],
chevy: ["Silverado", "Colorado"],
}
},
bikes: {
cheap: ['homemade'],
luxury: ['gucci']
},
legs: {
human: [],
dogs: [],
cats: []
}
}
transportation.bikes.contentAndname()
// I'm passing bikes through prototype