9.1 ToPrimitive

2010-05-04

mixed ToPrimitive(input:mixed, PreferredType:String=undefined)

Converts an object to a primitive value. Any input that's already a primitive will not be changed. the PreferredType is optional and the second parameter to [[DefaultValue]].

Code: (Meta Ecma)
function ToPrimitive(input, PreferredType){
if (typeof input != 'object') return input;
return input.[[DefaultValue]](PreferredType);
}