Skip to content

IE less then 8 shim algorithm

termi1uc1 edited this page Feb 1, 2012 · 10 revisions

#IE < 8 shim algorithm

Properties

  1. In your implementation of Object.defineProperty(obj, ...) for IE make sure you check for the ielt8 flag and set getters and setters as obj["get"/"set" + propertyName]

     ...
     if(Object.defineProperty.ielt8) {
       obj["get" + propertyName] = getter;
       obj["set" + propertyName] = setter;
     }
     ...
    
  2. Set Object.defineProperty.ielt8 = true;

  3. Use HTC technique for shim. Add style element with content:

     * { behavior : shim.htc }
    
  4. In HTC file:

     <PUBLIC:PROPERTY NAME="propertyName" GET="getter_propertyName" PUT="setter_propertyName" />
     <SCRIPT>
     var proto = Element.prototype;
     var getter_propertyName = proto.getpropertyName;
     var setter_propertyName = proto.setpropertyName;
     </SCRIPT>
    

Functions

  1. Create fake Node = {} and Node.prototype = {ielt8 : true} for IE < 8. You can use ielt8 flag for detect purpose

  2. Define functions as usual:

     Object.defineProperty(Node.prototype, "someFunction", {
       value : someFunction
     })
     // or
     Node.prototype.someFunction = someFunction;
    
  3. Use HTC technique for shim. Add style element with content:

     * { behavior : shim.htc }
    
  4. In HTC file:

     <SCRIPT>
     var Node_proto=window.Node.prototype;
     if(!this.someFunction)this.someFunction = Node_proto.someFunction;
     </SCRIPT>
    

Note:

  1. Create lightweight htc file. First line in file:

     <PUBLIC:COMPONENT lightWeight="true">
    
  2. TODO::

Clone this wiki locally