Mercurial > pymonkey
comparison docs/src/pymonkey.txt @ 114:87147faa031a
Added docs for define_property() and get_property().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 17 Aug 2009 03:02:51 -0700 |
parents | e616b4605db0 |
children | f4c550369332 |
comparison
equal
deleted
inserted
replaced
113:e616b4605db0 | 114:87147faa031a |
---|---|
101 >>> cx = pymonkey.Runtime().new_context() | 101 >>> cx = pymonkey.Runtime().new_context() |
102 >>> obj = cx.new_object() | 102 >>> obj = cx.new_object() |
103 >>> cx.define_property(obj, 'add', cx.new_function(add, 'add')) | 103 >>> cx.define_property(obj, 'add', cx.new_function(add, 'add')) |
104 >>> cx.evaluate_script(obj, 'add(1, 1);', '<string>', 1) | 104 >>> cx.evaluate_script(obj, 'add(1, 1);', '<string>', 1) |
105 2 | 105 2 |
106 | |
107 .. method:: define_property(object, name, value) | |
108 | |
109 Creates a new property on `object`, bypassing any JavaScript setters. | |
110 | |
111 .. method:: get_property(object, name) | |
112 | |
113 Finds the specified property on `object` and returns its value, | |
114 possibly invoking a JavaScript getter. | |
115 | |
116 Example: | |
117 | |
118 >>> cx = pymonkey.Runtime().new_context() | |
119 >>> obj = cx.new_object() | |
120 >>> cx.define_property(obj, 'beets', 'i like beets.') | |
121 >>> cx.get_property(obj, 'beets') | |
122 u'i like beets.' | |
123 | |
124 Note also that calling this function on undefined properties | |
125 yields :data:`undefined`: | |
126 | |
127 >>> cx.get_property(obj, 'carrots') | |
128 pymonkey.undefined | |
106 | 129 |
107 .. method:: get_object_private(object) | 130 .. method:: get_object_private(object) |
108 | 131 |
109 Returns the ``private_obj`` passed to :meth:`new_object()` | 132 Returns the ``private_obj`` passed to :meth:`new_object()` |
110 when `object` was first created. If it doesn't exist, ``None`` | 133 when `object` was first created. If it doesn't exist, ``None`` |