Webshims Lib

Polyfill only the incapable browsers

Demo/About/Documentation ES5

The es5 feature of Webshims Lib uses the ES5 shim by Kris Kowal (all object methods, which can't be used cross-browser are removed.).

The script implements the following methods:

Note: All methods added to the prototype object are visible inside of a for in loop, while native implementations aren't enumerable. (use hasOwnProperty)

$.webshims.ready('es5', function(){ [1, 2, 3].forEach(function(){ //do stuff }); });

Abstractions

Webshims Lib adds the following methods: $.webshims.objectCreate, $.webshims.defineProperty, $.webshims.defineProperties, $.webshims.getOwnPropertyDescriptor and corresponding support flags: Modernizr.objectAccessor (true in all modern Browsers including IE9, getters and setters can be used on all objects) and Modernizr.advancedObjectProperties (true in FF4, IE9, Chrome 10..., the full ES5 specification of defineProperty is implemented (including writeable, enumerable and configurable).

$.webshims.objectCreate(proto [, propertiesObject, options ])

$.webshims.objectCreate works very similar to Object.create

If propertiesObject is defined, the method goes through this object and sets writeable, enumerable and configurable to true, if the corresponding property is undefined.

After this, it will pass proto and propertiesObject to Object.create (if defined) or will use Crockfords begetObject-Method on the proto-object and then calls $.webshims.defineProperties with the returned object and the propertiesObject.

If you pass the options parameter and the Object already has a Options-property. The options-property on the object will be deeply extended otherwise an new options-property will be created.

If the object has a method called _create, it will call this method with options as first argument.

After this, the created object will be returned.

var carProto = { options: { foo: 'bar', baz: 'boom' }, wheels: 4, drive: function(){ this.isDriving = true; } }; var myCar = Object.create(carProto, { _create: { value: function(){ this.drive(); } }, jumps: { value: function(){ //implements jumping } }, {baz: 'jo'} ); //myCar will look like this: { //own property: options: { foo: 'bar', baz: 'jo' }, //prototype: wheels: 4, //prototype drive: function(){ this.isDriving = true; }, //own property: _create: function(){ this.drive(); }, //own property: jumps: function(){ //implements jumping }, //own property: isDriving: true }

$.webshims.defineProperties (object, props)

$.webshims.defineProperties works similar to Object.defineProperties

It will go through the props properties and will set writeable, enumerable and configurable to true, if they are undefined.

After this either Object.defineProperties will be invoked or legacy code is used.