I'd like to fake a namespace in Javascript. This can be done as follows:
var cars = {};
cars.car = function() {
...
}
cars.car.prototype = {
drive: function() {
...
}
}
Works fine. My question, however, is if I can directly fill the whole namespace with JSON, like this:
var cars = {
car: function() {
...
},
car.prototype: {
drive: function() {
...
}
}
}
That doesn't work. Can I somehow declare the prototype of car inside the car() function? Or is there another way to solve this?