/ Published in: JavaScript
Xccessors is a JavaScript shim that implements the legacy methods for defining and looking up object accessors (getters and setters) of objects in JavaScript using ECMAScript 3.1’s accessors standard. This is aimed at adding support for the legacy method in IE8 RC1.
The code is made to have as small of a footprint as possible. YUI minified, the code is 556 bytes. Here is the minified version:
(function(b,d,c){function a(f,g,e){if(f in d&&!(g in {})){d[c][g]=Element[c][g]=Window[c][g]=HTMLDocument[c][g]=e}}a(b[0],b[2],function(f,e){d[b[0]](this,f,{get:e})});a(b[0],b[3],function(f,e){d[b[0]](this,f,{set:e})});a(b[1],b[4],function(e){return d[b[1]](this,e).get||d[b[1]](this.constructor.prototype,e).get});a(b[1],b[5],function(e){return d[b[1]](this,e).set||d[b[1]](this.constructor.prototype,e).set})})(["defineProperty","getOwnPropertyDescriptor","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],Object,"prototype");
The code is made to have as small of a footprint as possible. YUI minified, the code is 556 bytes. Here is the minified version:
(function(b,d,c){function a(f,g,e){if(f in d&&!(g in {})){d[c][g]=Element[c][g]=Window[c][g]=HTMLDocument[c][g]=e}}a(b[0],b[2],function(f,e){d[b[0]](this,f,{get:e})});a(b[0],b[3],function(f,e){d[b[0]](this,f,{set:e})});a(b[1],b[4],function(e){return d[b[1]](this,e).get||d[b[1]](this.constructor.prototype,e).get});a(b[1],b[5],function(e){return d[b[1]](this,e).set||d[b[1]](this.constructor.prototype,e).set})})(["defineProperty","getOwnPropertyDescriptor","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],Object,"prototype");
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* @name Xccessors @version 0.0.3 @desc Shim that implements __defineGetter__, __defineSetter__, __lookupGetter__, and __lookupSetter__ in browsers that have ECMAScript 3.1 accessor support but not the legacy methods @license http://www.gnu.org/licenses/lgpl.html @author Elijah Grey - eligrey.com */ (function (methods, o, f) { function extendMethod(reqMethod, method, fun) { if (reqMethod in o && !(method in {})) o[f][method] = Element[f][method] = Window[f][method] = HTMLDocument[f][method] = fun; }; extendMethod(methods[0], methods[2], function (prop, fun) { o[methods[0]](this, prop, { get: fun }); }); extendMethod(methods[0], methods[3], function (prop, fun) { o[methods[0]](this, prop, { set: fun }); }); extendMethod(methods[1], methods[4], function (prop) { return o[methods[1]](this, prop).get || o[methods[1]](this.constructor.prototype, prop).get; }); extendMethod(methods[1], methods[5], function (prop) { return o[methods[1]](this, prop).set || o[methods[1]](this.constructor.prototype, prop).set; }); })(["defineProperty", "getOwnPropertyDescriptor","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"], Object, "prototype");
URL: http://eligrey.com/projects/xccessors/