Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] property instead of method
- From: sclay at ufl.edu (Steve Clay)
- Subject: [Javascript] property instead of method
- Date: Thu May 25 09:41:10 2006
Wednesday, May 24, 2006, 6:17:30 PM, liorean wrote: > allows getters and setters, so for gecko based browsers it's doable, > but not for iew, op or saf. <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Creating_New_Objects:Defining_Getters_and_Setters> Is there power in these beyond syntactic sugar? The above URL shows how to create a dynamic "year" property to Date, and I can see that'd be handy for something like "myDate.year += 10" but what could you do that you couldn't by adding custom methods getYear and setYear? Can you add functions to existing getters/setters? Seems to me that a language feature that disguises methods as properties just serves to obfuscate interfaces, but I guess these are already out there: Shouldn't Element.getChildNodes be a method if hasChildNodes is? How do you test if a property is read-only? You can at least test for the existence of a setSomething method. I'm sure "dynamic" properties do make our lives easier, it's just annoying to have code mysteriously and quietly fail because you tried to set a property that was read-only only in certain browsers/moon phases and the only way to know is to break out the documentation and start browser sniffing... Steve -- http://mrclay.org/
- Follow-Ups:
- [Javascript] property instead of method
- From: liorean
- [Javascript] property instead of method
- References:
- [Javascript] property instead of method
- From: Geoff Knutzen
- [Javascript] property instead of method
- From: liorean
- [Javascript] property instead of method
- Prev by Date: JavaScript debugging Was: [Javascript] Getting object property names as a string
- Next by Date: [Javascript] property instead of method
- Previous by thread: [Javascript] property instead of method
- Next by thread: [Javascript] property instead of method
- Index(es):