I have this function that returns an object:
String.prototype.test = function(a,b){
var ob = {};
ob[a] = b;
return this || ob
}
//usage
"Test".test('hi','hello');
If .hi isnt attached to test, i want it to return the string.
So with that example I would need:
"Test".test('hi','hello').hi;//returns: hello
To work, but then I also need:
"Test".test('hi','hello'); //returns Test
To work, I tried using || in the return but it’s not working. Thanks for the help.
It’s impossible to make the return value depend on what happens with the returned value.
You could however return a
Stringobject with a propertyhi:Demo: