JSFiddle - React, Tailwind, and code Playground
by lbstr
HTML
<div id="r">
</div>
JavaScript
var A = function(){};
A.prototype.one = function(callFoo){
(callFoo ? this.foo : this.bar).call(this);
};
A.prototype.two = function(callFoo){
this[(callFoo ? "foo" : "bar")]();
};
A.prototype.three = function(callFoo){
(callFoo ? this.foo : this.bar)();
};
A.prototype.four = function(){
(false || this.foo)();
};
A.prototype.foo = function(){
if (this.log !== undefined) {
this.log('foo');
}
else {
$('#r').append('<div>this.log is undefined</div>');
}
};
A.prototype.bar = function(){
if (this.log !== undefined) {
this.log('bar');
}
else {
$('#r').append('<div>this.log is undefined</div>');
}
};
A.prototype.log = function(msg){
$('#r').append('<div>' + msg + '</div>');
};
var a = new A();
a.one(true);
a.one(false);
a.two(true);
a.two(false);
a.three(true);
a.three(false);
a.four();