Skip to content

Instantly share code, notes, and snippets.

Created March 30, 2016 21:47
Show Gist options
  • Save anonymous/ab2ae86aca9e721e6eaec56050f4832b to your computer and use it in GitHub Desktop.
Save anonymous/ab2ae86aca9e721e6eaec56050f4832b to your computer and use it in GitHub Desktop.
JS Bin inheritance JS // source https://jsbin.com/tiwixo
<!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>
(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