Created
May 31, 2011 15:45
-
-
Save bellbind/1000718 to your computer and use it in GitHub Desktop.
[js]Missing ECMAScript5 standard function for Opera11 and Safari5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function (global) { | |
| // Missing ECMAScript5 standard functions for Opera and Safari | |
| // support getter/setter with non standard funcs | |
| // add the script tag to html at first: | |
| // <script src="https://gist.github.com/raw/1000718/es5compat-gs.js" | |
| // ></script> | |
| // dummy Object protection interface for Opera11 and Safari5 | |
| Object.isFrozen = ( | |
| Object.isFrozen || function isFrozen(obj) {return false;}); | |
| Object.isSealed = ( | |
| Object.isSealed || function isSealed(obj) {return false;}); | |
| Object.isExtensible = ( | |
| Object.isExtensible || function isExtensible(obj) {return false;}); | |
| Object.freeze = (Object.freeze || function freeze(obj) {return obj;}); | |
| Object.seal = (Object.seal || function seal(obj) {return obj;}); | |
| Object.preventExtensions = ( | |
| Object.preventExtensions || function preventExtensions(obj) { | |
| return obj;}); | |
| // dummy Object property interface for Opera11 | |
| var oproto = Object.prototype; | |
| var hasOwnProperty = Object.prototype.hasOwnProperty; | |
| Object.keys = (Object.keys || function keys(obj) { | |
| var ret = []; | |
| for (var name in obj) { | |
| if (hasOwnProperty.call(obj, name)) ret.push(name); | |
| } | |
| return ret; | |
| }); | |
| Object.getOwnPropertyNames = ( | |
| Object.getOwnPropertyNames || function getOwnPropertyNames(obj) { | |
| return Object.keys(obj); | |
| }); | |
| Object.getOwnPropertyDescriptor = ( | |
| Object.getOwnPropertyDescriptor || | |
| function getOwnPropertyDescriptor(obj, name) { | |
| if (!hasOwnProperty.call(obj, name)) return undefined; | |
| if ("__lookupGetter__" in oproto && | |
| "__lookupSetter__" in oproto) { | |
| var getter = oproto.__lookupGetter__.call(obj, name); | |
| var setter = oproto.__lookupSetter__.call(obj, name); | |
| if (getter || setter) return { | |
| get: getter, set: setter, | |
| enumerable: true, configurable: false}; | |
| } | |
| return { | |
| value: obj[name], writable: true, | |
| enumerable: true, configurable: true}; | |
| }); | |
| Object.defineProperty = ( | |
| Object.defineProperty || function defineProperty(obj, name, desc) { | |
| if ("get" in desc || "set" in desc) { | |
| if ("get" in desc && "__defineGetter__" in oproto) { | |
| oproto.__defineGetter__.call(obj, name, desc.get); | |
| } | |
| if ("set" in desc && "__defineSetter__" in oproto) { | |
| oproto.__defineSetter__.call(obj, name, desc.set); | |
| } | |
| } else { | |
| obj[name] = desc.value; | |
| } | |
| return obj; | |
| }); | |
| Object.defineProperties = ( | |
| Object.defineProperties || function defineProperties(obj, props) { | |
| Object.getOwnPropertyNames(props).forEach(function (name) { | |
| Object.defineProperty(obj, name, props[name]); | |
| }); | |
| return obj; | |
| }); | |
| Object.create = (Object.create || function create(proto, props) { | |
| var ctor = function () {}; | |
| ctor.prototype = proto; | |
| return Object.defineProperties(new ctor(), props || {}); | |
| }); | |
| Object.getPrototypeOf = ( | |
| Object.getPrototypeOf || function getPrototypeOf(obj) { | |
| return obj.constructor.prototype; | |
| }); | |
| // mimic bind for Opera11 and Safari5 | |
| // support: currying. curryied result called with "new". | |
| // non support: "length" property. curryied result has no "prototype" e.g.: | |
| // var curr = ctor.bind(null, 0); (new curr() instanceof curr) === false; | |
| var slice = Array.prototype.slice; | |
| Function.prototype.bind = (Function.prototype.bind || function bind(thisp) { | |
| var func = this; | |
| var bounds = slice.call(arguments, 1); | |
| var curry = function () { | |
| var args = bounds.concat(slice.call(arguments)); | |
| var callAsNew = this instanceof curry; | |
| return func.apply(callAsNew ? this : (thisp || this), args); | |
| }; | |
| var pad = function () {}; // pad is required for opera's "instanceof" | |
| pad.prototype = func.prototype; | |
| curry.prototype = new pad(); | |
| return curry; | |
| }); | |
| })(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function (global) { | |
| // Missing ECMAScript5 standard functions for Opera and Safari | |
| // add the script tag to html at first: | |
| // <script src="https://gist.github.com/raw/1000718/es5compat.js" | |
| // ></script> | |
| // dummy Object protection interface for Opera11 and Safari5 | |
| Object.isFrozen = ( | |
| Object.isFrozen || function isFrozen(obj) {return false;}); | |
| Object.isSealed = ( | |
| Object.isSealed || function isSealed(obj) {return false;}); | |
| Object.isExtensible = ( | |
| Object.isExtensible || function isExtensible(obj) {return false;}); | |
| Object.freeze = (Object.freeze || function freeze(obj) {return obj;}); | |
| Object.seal = (Object.seal || function seal(obj) {return obj;}); | |
| Object.preventExtensions = ( | |
| Object.preventExtensions || function preventExtensions(obj) { | |
| return obj;}); | |
| // dummy Object property interface for Opera11 | |
| var hasOwnProperty = Object.prototype.hasOwnProperty; | |
| Object.keys = (Object.keys || function keys(obj) { | |
| var ret = []; | |
| for (var name in obj) { | |
| if (hasOwnProperty.call(obj, name)) ret.push(name); | |
| } | |
| return ret; | |
| }); | |
| Object.getOwnPropertyNames = ( | |
| Object.getOwnPropertyNames || function getOwnPropertyNames(obj) { | |
| return Object.keys(obj); | |
| }); | |
| Object.getOwnPropertyDescriptor = ( | |
| Object.getOwnPropertyDescriptor || | |
| function getOwnPropertyDescriptor(obj, name) { | |
| if (!hasOwnProperty.call(obj, name)) return undefined; | |
| return { | |
| value: obj[name], | |
| writable: true, | |
| enumerable: true, | |
| configurable: true | |
| }; | |
| }); | |
| Object.defineProperty = ( | |
| Object.defineProperty || function defineProperty(obj, name, desc) { | |
| obj[name] = desc.value; | |
| return obj; | |
| }); | |
| Object.defineProperties = ( | |
| Object.defineProperties || function defineProperties(obj, props) { | |
| Object.getOwnPropertyNames(props).forEach(function (name) { | |
| Object.defineProperty(obj, name, props[name]); | |
| }); | |
| return obj; | |
| }); | |
| Object.create = (Object.create || function create(proto, props) { | |
| var ctor = function () {}; | |
| ctor.prototype = proto; | |
| return Object.defineProperties(new ctor(), props || {}); | |
| }); | |
| Object.getPrototypeOf = ( | |
| Object.getPrototypeOf || function getPrototypeOf(obj) { | |
| return obj.constructor.prototype; | |
| }); | |
| // mimic func.bind for Opera11 and Safari5 | |
| // support: currying. curryied result called with "new". | |
| // non support: "length" property. curryied result has no "prototype" e.g.: | |
| // var curr = ctor.bind(null, 0); (new curr() instanceof curr) === false; | |
| var slice = Array.prototype.slice; | |
| Function.prototype.bind = (Function.prototype.bind || function bind(thisp) { | |
| var func = this; | |
| var bounds = slice.call(arguments, 1); | |
| var curry = function () { | |
| var args = bounds.concat(slice.call(arguments)); | |
| var callAsNew = this instanceof curry; | |
| return func.apply(callAsNew ? this : (thisp || this), args); | |
| }; | |
| var pad = function () {}; // pad is required for opera's "instanceof" | |
| pad.prototype = func.prototype; | |
| curry.prototype = new pad(); | |
| return curry; | |
| }); | |
| })(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment