raptor-polyfill
Version:
Polyfills for various EcmaScript 5 and EcmaScript 6 methods distributed as CommonJS modules that can be require'd individually or as a whole.
15 lines (14 loc) • 471 B
JavaScript
var prepareString = "a"[0] != "a";
// ES5 9.9
// http://es5.github.com/#x9.9
module.exports = function (o) {
if (o == null) { // this matches both null and undefined
throw new TypeError("can't convert "+o+" to object");
}
// If the implementation doesn't support by-index access of
// string characters (ex. IE < 9), split the string
if (prepareString && typeof o == "string" && o) {
return o.split("");
}
return Object(o);
};