Link to home
Start Free TrialLog in
Avatar of eobet
eobet

asked on

Creating currentStyle in Mozilla?

Hello!

I've seen usage in code on Google searches of something called __defineGetter__ and __defineSetter__, but I have never gotten this to work (HTMLElement.prototype.__defineGetter__("functionName" function... etc. etc.)

However, I did get a response from HTMLElement.prototype.currentStyle = function() { return document.defaultView.getComputedStyle(this, ''); }; but Mozilla only said that my element didn't have any properties when I tried it.

Calling the function explicitly (ie. document.defaultView.getComputedStyle(something.something.something, '').something) DOES however work.

What am I doing wrong in my prototype function?
ASKER CERTIFIED SOLUTION
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way, using defineGetter for the currentStyle is much better for you than the older syntax because it enables currentStyle as a property of elements rather than as a function, so it's then cross-browser with IE. But I guess you knew that.
Avatar of eobet
eobet

ASKER

Odd... yesterday, when I was told about these abilities of Mozilla, I got this line:

HTMLElement.prototype.__defineGetter__("currentStyle", function() { return document.defaultView.getComputedStyle(this, null); });

And I couldn't get it to work. Today, after having pasted your line, and noted the similarities, I again tried the old line. And it did work. Must have done something odd yesterday.

Anyway, thanks for clearing this up!
Yeh the prototying abilities of Mozilla are awesome!!
Any Object can be prototyped as you know, not just Core Javscript objects! If only people knew about the power of Mozilla.....
Avatar of eobet

ASKER

If only Mozilla could have implemented currentStyle in the first place...

;)