JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Output</h1>
<h2>First</h2>
<p id="first"></p>
<h2>Second</h2>
<p id="second"></p>
JavaScript
var personPrototype = {
hello: function () {
return "Hello " + name;
}
}
function PersonInConstructor(name) {
this.name = name;
self.prototype = personPrototype;
}
function Person(name) {
this.name = name;
}
Person.prototype = personPrototype;
$(function() {
var firstPerson = new PersonInConstructor("Alan");
var secondPerson = new Person("Alan");
try {
output1 = firstPerson.hello();
} catch (e) {
output1 = e.message;
}
try {
output2 = secondPerson.hello();
} catch (e) {
output2 = e.message;
}
$("#first").html(output1);
$("#second").html(output2);
});