I don't think that exists. Instead use the defaults operator `||' like so:

var x = obj.test || 10;

------------------------
Gary Katsevman
Computer Science Undergraduate
Northeastern University
gkatsev.com



On Tue, Apr 5, 2011 at 10:38, mcot <[email protected]> wrote:
> I was wondering if you could have a function serve as the default
> function that gets called when a property is accessed.
>
> Lets say property test1 does not exist:
>
> var x = someObj.test1; // undefined
>
>
> What I want is something like this:
>
> someObj.defaultGetter = function(prop) {
>
>     // prop is the string "test1" when this gets called.
>     return 10;
> }
>
> var x = someObj.test1  // 10
>
> I am 99% sure this does not exist in the language, but I just wanted
> to check and make sure I am not missing something that adds this
> capability in the ES5 spec.
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to