By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

Final properties and methods?

P: n/a
VK
If any way to implement a cross-browser method/property protection in an
object?

Say:

function myObject() {
this.myProperty = "A value that shouldn't be overridden in instances."
}

Mozilla (I believe) still has watch() method, that does the job semi-ok (you
cannot really protect a property, but you can immediately restore its
original value).

IE doesn't have watch() method though.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK wrote:
Mozilla (I believe) still has watch() method, that does the job semi-ok (you
cannot really protect a property, but you can immediately restore its
original value).


Actually Mozilla also supports constants which might work out better:
const foo = "A value that shouldn't be changed";
Unfortunally Internet Explorer doesn't understand the const keyword
and will therefore make an error.
Jul 23 '05 #2

P: n/a
On Sat, 11 Dec 2004 12:40:59 +0100, Ulrik Skovenborg <"skovenborg at frac
dot dk"> wrote:

[snip]
Unfortunally Internet Explorer doesn't understand the const keyword


Neither does Opera, and I doubt many other browsers (if any) will, either.

To VK: No, you can't mark properties as read-only. You'll either have to
trust client software to respect a "Don't modify this value" notice, or
hide the value internally and use a function. Go with the former, if you
can.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.