Class Index | File Index

Classes


Built-In Class Object

Extensions to built in Object class.

Method Summary
Method Attributes Method Name and Description
<static>  
Object.defineProperty(obj, name, description)

Define a property on an object with flags.

Method Detail
<static> Object.defineProperty(obj, name, description)

Define a property on an object with flags. This allows you to create read-only or non-enumerable properties on your javascript objects.

Parameters:
obj

Object on which to define the property

name

property name

description

Property descriptor.

A property descriptor is an object with some of the following keys

All values default to false or undefined. If either writable or value exist then neither getter nor setter are allowed.

A getter function is one which is called and should return the current value of the property. A setter is called with the argument to set the property too, but you can set it do a derivative of that value, or ignore it completly. Both getter and setter are called with "this" set to the object in question.

function MyObj() {
  var prop = 0;
  Object.defineProperty(
    myobj, 
    "prop",
    { getter: function() { return prop },
      setter: function(x) { prop = x * 2; return prop; },
      enumerable: false,
      configurable: true
    }
  );
}

If configurable is false, then any further attempts to call #defineProperty on that property will result in an exception.


Documentation generated by JsDoc Toolkit 2.1.0 on Wed Nov 18 2009 19:05:15 GMT-0000 (UTC)