Next IE 8 Release Candidate to have updated getter/setter support and DOM prototypes
Written by on January 14th, 2009 in Uncategorized.
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:
-
-
// Create a property descriptor object
-
var posPropDesc = new Object();
-
// Define the getter
-
posPropDesc.getter = function ()
-
{
-
var coords = new Object();
-
coords.x = parseInt(this.currentStyle.left);
-
coords.y = parseInt(this.currentStyle.top);
-
coords.w = parseInt(this.currentStyle.width);
-
coords.h = parseInt(this.currentStyle.height);
-
return JSON.stringify(coords);
-
}
-
// Define the setter
-
posPropDesc.setter = function (JSONString)
-
{
-
var coords = JSON.parse(JSONString);
-
if (coords.x) this.style.left = coords.x + “px”;
-
if (coords.y) this.style.top = coords.y + “px”;
-
if (coords.w) this.style.width = coords.w + “px”;
-
if (coords.h) this.style.height = coords.h + “px”;
-
}
-
// Define the new accessor property "JSONposition" on a new image
-
var img = Object.defineProperty(new Image(), “JSONposition”, posPropDesc);
-
img.src = “…”;
-
// Call the new property
-
img.JSONposition = ‘{"w":400,"h":100}’;
-
// Read the image’s current position
-
console.log(img.JSONposition);
-
-
Object.defineProperty( document.body, “secondChild”,
-
{
-
getter: function ()
-
{
-
return this.firstChild.nextSibling;
-
},
-
setter: function ( element )
-
{
-
throw new Error(“Sorry! This property can’t be “ +
-
“set. Better luck next time.”);
-
}
-
} );
-
// Changed my mind: don’t be so strict about throwing
-
// an error when setting this property…
-
Object.defineProperty( document.body, “secondChild”,
-
{ setter: undefined } );
-
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