I'm trying to figure out how to make a polyfill for dataset and I think I need to use get and set to define the function. How would the syntax of get/set be when trying to add them to Element.prototype
? The examples on MDN shows a local variable, but how do you use them to add to Element.prototype
?
Object.defineProperty {Element.prototype, "dataset",
get: function() { /* return value */ }
, set: function(newVal) { /* set somehow w/ setAttribute or jQuery */ }
}
I'd like to either route the getter/setter methods to $.attr() the example above I just related them to .data() or (better) the native setAttribute
and getAttribute
.
There is one polyfill for dataset here but it only supports standards-compliant browsers (not IE8 or less). I want to do one the avoids the use of __defineGetter__
(I think that's the issue in IE8). I think defineProperty may be the appropriate method, and I can use the ES5 Shim to polyfill that. How would I use defineProperty to do this?