我有这个返回对象的函数:
String.prototype.test = function(a,b){
var ob = {};
ob[a] = b;
return this || ob
}
//usage
"Test".test('hi','hello');
如果.hi
没有附加到测试,我希望它返回字符串。
因此,对于该示例,我需要:
"Test".test('hi','hello').hi;//returns: hello
工作,但我还需要:
"Test".test('hi','hello'); //returns Test
为了工作,我尝试||
在退货中使用,但它不起作用。谢谢您的帮助。