JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<div id="answer1"></div>
<div id="answer2"></div>
<div id="answer3"></div>
<div id="answer4"></div>
JavaScript
var Parent = function() {};
Object.defineProperty(Parent.prototype, "answer", {
value: function() { return 42; }
});
var Child = function() {};
Child.prototype = Object.create(Parent.prototype, {
answer: {
value: function() { return 0; }
}
});
//as expected
test1 = new Parent();
$("#answer1").text(test1.answer());
test2 = new Child();
$("#answer2").text(test2.answer());
var Parent2 = function() {};
Object.defineProperty(Parent2.prototype, "answer", {
value: function() { return 42; }
});
var Child2 = function() {};
Child2.prototype = Object.create(Parent2.prototype);
test3 = new Parent2();
$("#answer3").text(test3.answer());
test4 = new Child2();
test4.answer = function() { return 0; };
$("#answer4").text(test4.answer());