JSFiddle - React, Tailwind, and code Playground
by grundez
HTML
<div id="cow1"></div>
<div id="cow2"></div>
JavaScript
function Cow(){
var speak = function(){
return "Moo";
};
return {
speak: speak
};
}
var cow1 = Cow();
// overwriting the speak method in the interface returned does not alter the internal variable
cow1.speak = function(){
return "Bar";
};
var cow2 = Cow();
document.getElementById("cow1").innerHTML = cow1.speak();
document.getElementById("cow2").innerHTML = cow2.speak();