JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<body>
<div class="container">
<h1>Javascript interface try</h1>
<button id="customerData" class="btn btn-sm btn-success">Show customer data</button>
</div>
</body>
JavaScript
"use strict";
function PersonInterface(){
}
PersonInterface.prototype.getName = function(){
throw typeof(Error) !== 'undefined'?
new Error(" Interface Person: method getName() unimplemented!")
: " Interface Person: method getName() unimplemented!";
};
PersonInterface.prototype.getSurname = function(){
throw typeof(Error) !== 'undefined'?
new Error(" Interface Person: method getSurname() unimplemented!")
: " Interface Person: method getSurname() unimplemented!";
};
function Customer(name, surname){
PersonInterface.call(this);
this.__name = name;
this.__surname = surname;
}
Customer.prototype = Object.create(PersonInterface.prototype);
Customer.prototype.getName = function(){
return this.__name;
};
Customer.prototype.getSurname = function(){
return this.__surname;
};
$(document).ready(function(){
$("#customerData").click(function(){
var customer = new Customer("John", "Smith");
if (!(customer instanceof PersonInterface)){
throw typeof(Error) !== 'undefined'?
new Error(" Interface Person not implemented!")
: " Interface Person not implemented!";
}
alert(customer.getName() + " " + customer.getSurname());
});
});