/    Sign up×
Community /Pin to ProfileBookmark

Getter & Setter implementation for Explorer wanted.

I know this is not a JScript forum, but I was wondering if there is a way of implementing getter/setter functionality for properties for JScript.

With JavaScript you can for example say:

[CODE]var myVar getter=function(){bla bla bla}[/CODE]

This works fine for Firefox, but IE6 and IE7 is a no go. Is there a workaround, other than using functions like getMyVar() and setMyVar()?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DokAug 20.2007 — Getters and setters are a custom extension of firefox although I think ECMA actually endorse them. You can use the concept of closures to mimick private methods as you know them from Java or C++ but its a pretty advanced topic. My suggestion is to just avoid setters/getters all together when coding in JavaScript.
Copy linkTweet thisAlerts:
@josamotoauthorAug 20.2007 — Getters and setters are really nice if you for example want to validate a value before assigning it's value to the property. If I use a getVar() setVar(), it sadly does not hide the variable it sets.

I suppose it is the only alternative though. Thanks for your reply. ?
Copy linkTweet thisAlerts:
@DokAug 20.2007 — The only way to truly hide variables is to use closures.

Have a look at the watch method of FF and the onpropertychange of IE. You can use these events to watch for a property change in a object.
×

Success!

Help @josamoto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...