I’m now pleased to announce that with the upcoming Release Candidate of Internet Explorer 8, we not only have a high-quality DOM prototypes implementation, but we’ve been able to change the getter/setter implementation to follow the draft ECMAScript 3.1 standard. While our JavaScript engine and DOM won’t have support for all of the ECMAScript 3.1 enhancements in this release, it does mean that web developer code written to add getters and setters to the DOM in Internet Explorer 8 will continue to work now and into the future, since that code will be based on web-standards.

I’m very excited about this new capability in IE8! To help you get started, I’ve written a few articles that provide an introduction to DOM prototypes and getter/setters (and the new syntax that will be publicly available in the upcoming release candidate build):

Responding to Change: Updated Getter/Setter Syntax in IE8 RC 1 Travis Leithead, IE PM.

To see the new API at work, you can check out an example:

JAVASCRIPT:

  1.  
  2. // Create a property descriptor object
  3. var posPropDesc = new Object();
  4. // Define the getter
  5. posPropDesc.getter = function ()
  6. {
  7.   var coords = new Object();
  8.   coords.x = parseInt(this.currentStyle.left);
  9.   coords.y = parseInt(this.currentStyle.top);
  10.   coords.w = parseInt(this.currentStyle.width);
  11.   coords.h = parseInt(this.currentStyle.height);
  12.   return JSON.stringify(coords);
  13. }
  14. // Define the setter
  15. posPropDesc.setter = function (JSONString)
  16. {
  17.   var coords = JSON.parse(JSONString);
  18.   if (coords.x) this.style.left   = coords.x + “px”;
  19.   if (coords.y) this.style.top    = coords.y + “px”;
  20.   if (coords.w) this.style.width  = coords.w + “px”;
  21.   if (coords.h) this.style.height = coords.h + “px”;
  22. }
  23. // Define the new accessor property "JSONposition" on a new image
  24. var img = Object.defineProperty(new Image(), “JSONposition”, posPropDesc);
  25. img.src = “…”;
  26. // Call the new property
  27. img.JSONposition = ‘{"w":400,"h":100}’;
  28. // Read the image’s current position
  29. console.log(img.JSONposition);
  30.  
  31. Object.defineProperty( document.body, “secondChild”,
  32. {
  33.   getter: function ()
  34.   {
  35.     return this.firstChild.nextSibling;
  36.   },
  37.   setter: function ( element )
  38.   {
  39.     throw new Error(“Sorry! This property can’t be “ +
  40.                     “set. Better luck next time.”);
  41.   }
  42. } );
  43. // Changed my mind: don’t be so strict about throwing
  44. // an error when setting this property…
  45. Object.defineProperty( document.body, “secondChild”,
  46.                        { setter: undefined } );
  47.  

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/511778992/next-ie-8-release-candidate-to-have-updated-gettersetter-support-and-dom-prototypes

Comments are closed.



Site Navigation