Created
March 30, 2016 21:47
-
-
Save anonymous/ab2ae86aca9e721e6eaec56050f4832b to your computer and use it in GitHub Desktop.
JS Bin inheritance JS // source https://jsbin.com/tiwixo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="inheritance JS"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
(function() { | |
'use strict'; | |
function Vehicle(name) { | |
this.name = name; | |
this.anotherDrive = function(){ | |
console.log('ánother drive'); | |
}; | |
} | |
Vehicle.prototype.drive = function () { | |
console.log(Vehicle.name + ' is driving...'); | |
}; | |
function Car(name) { | |
this.name = name; | |
this.beep = function() { | |
console.log(Car.name + ' goes beep'); | |
}; | |
} | |
Car.prototype = new Vehicle(); | |
var car = new Car('toyota prius'); | |
car.beep(); | |
car.drive(); | |
Vehicle.prototype.drive = function() { | |
console.log(Vehicle.name + ' is driving differently again'); | |
}; | |
car.beep(); | |
car.drive(); | |
var vehicle = new Vehicle('generic vehicle'); | |
vehicle.drive(); | |
})(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">(function() { | |
'use strict'; | |
function Vehicle(name) { | |
this.name = name; | |
this.anotherDrive = function(){ | |
console.log('ánother drive'); | |
}; | |
} | |
Vehicle.prototype.drive = function () { | |
console.log(Vehicle.name + ' is driving...'); | |
}; | |
function Car(name) { | |
this.name = name; | |
this.beep = function() { | |
console.log(Car.name + ' goes beep'); | |
}; | |
} | |
Car.prototype = new Vehicle(); | |
var car = new Car('toyota prius'); | |
car.beep(); | |
car.drive(); | |
Vehicle.prototype.drive = function() { | |
console.log(Vehicle.name + ' is driving differently again'); | |
}; | |
car.beep(); | |
car.drive(); | |
var vehicle = new Vehicle('generic vehicle'); | |
vehicle.drive(); | |
})();</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
function Vehicle(name) { | |
this.name = name; | |
this.anotherDrive = function(){ | |
console.log('ánother drive'); | |
}; | |
} | |
Vehicle.prototype.drive = function () { | |
console.log(Vehicle.name + ' is driving...'); | |
}; | |
function Car(name) { | |
this.name = name; | |
this.beep = function() { | |
console.log(Car.name + ' goes beep'); | |
}; | |
} | |
Car.prototype = new Vehicle(); | |
var car = new Car('toyota prius'); | |
car.beep(); | |
car.drive(); | |
Vehicle.prototype.drive = function() { | |
console.log(Vehicle.name + ' is driving differently again'); | |
}; | |
car.beep(); | |
car.drive(); | |
var vehicle = new Vehicle('generic vehicle'); | |
vehicle.drive(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment