Final properties and methods?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VK

    Final properties and methods?

    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.


  • Ulrik Skovenborg

    #2
    Re: Final properties and methods?

    VK wrote:[color=blue]
    > 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).[/color]

    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.

    Comment

    • Michael Winter

      #3
      Re: Final properties and methods?

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

      [snip]
      [color=blue]
      > Unfortunally Internet Explorer doesn't understand the const keyword[/color]

      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.

      Comment

      Working...