Looking at the mozilla documentation, looking at the regular expression example (headed "Creating an array using the result of a match"), we have statements like:
input: A read-only property that reflects the original string against which the regular expression was matched.
index: A read-only property that is the zero-based index of the match in the string.
etc… is it possible to create your own object in JavaScript which will have read-only properties, or is this a privilege reserved to built-in types implemented by particular browsers?
Edit: Since this answer was written, a new, better way using
Object.definePropertyhas been standardized in EcmaScript 5, with support in newer browsers. See Aidamina’s answer. If you need to support ‘older’ browsers, you could use one of the methods in this answer as a fallback.In Firefox, Opera 9.5+, and Safari 3+, Chrome and IE (tested with v11) you can define getter and setter properties. If you only define a getter, it effectively creates a read-only property. You can define them in an object literal or by calling a method on an object.
If you already have an object, you can call
__defineGetter__and__defineSetter__:Of course, this isn’t really useful on the web because it doesn’t work in Internet Explorer.
You can read more about it from John Resig’s blog or the Mozilla Developer Center.