Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

http://jsfiddle.net/sxpVG/

var ford = new Car({
    model: 'ford',
    power: '20'
});
var tesla = new Car({
    model: 'tesla',
    power: '60'
});
var oldCar = new Car({});

ford.drive();
tesla.drive();
oldCar.drive();

function Car(params) {
    this.model = params.model || 'Lada';
    this.power = params.power || '0';

    this.drive = function () {
        console.log('driving a ' + this.model + ' with power ' + this.power);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment