0
-=
= JavaScript MOP Utilities
0
+=
JavaScript MOP Utilities
0
-Defines some utilities for JavaScript metaprogramming:
0
+Defines some utilities for JavaScript metaprogramming. See the specs
0
- MOP.delegate(target, propertyName, methods)
0
- For each name in `methods`, defines a method on `target` with this
0
- name, that delegates to the method of the `propertyName` property
0
- of `target` with the same name.
0
+== Method Definition Methods
0
-And these for asynchronous metaprogramming:
0
+ MOP.Object(object).accessor(propertyName)
0
+ MOP.Class(klass).accessor(propertyName)
0
+Attaches +getXXX+ and +setXXX+ to +object+ or to
0
+<code>klass.prototype</code>. +XXX+ is the capitalized form of
0
++propertyName+; for example, +name+ generates +getName+ and +setName+.
0
+ MOP.Object(object).getter(propertyName)
0
+ MOP.Class(klass).getter(propertyName)
0
+Attaches +getXXX+ to +object+ or to <code>klass.prototype</code>.
0
++XXX+ is the capitalized form of +propertyName+; for example, +name+
0
+ MOP.Object(object).delegate(propertyName, methods)
0
+ MOP.Class(klass).delegate(propertyName, methods)
0
+For each name in +methods+, defines a method on +object+ or
0
+<code>klass.prototype</code> with this name, that delegates to the
0
+method of the +propertyName+ property of +object+ with the same name.
0
+== Method Wrapper Methods
0
+ MOP.Object(object).method(methodName).guardBy(guardFn)
0
+ MOP.Class(klass).method(methodName).guardBy(guardFn)
0
+Replaces <code>object.methodName</code> by a method that calls the
0
+underlying method only if +guardFn+, applied to the same arguments,
0
+ MOP.Object(object).method(methodName).guardUntil(guardFn, ms)
0
+ MOP.Class(klass).method(methodName).guardUntil(guardFn, ms)
0
+A call to <code>object.methodName</code> causes a timer to
0
+periodically call +guardFn+ until it returns a true value, at which
0
+point the underlying function is called, and the timer stops.
0
+ MOP.Object(object).method(methodName).time(guardFn)
0
+ MOP.Class(klass).method(methodName).time(guardFn)
0
+Replaces <code>object.methodName</code> by a method that calls the
0
+underlying function, and prints to the console the name of the method
0
+and the time it took to execute.
0
+ MOP.Object(object).method(methodName).trace(guardFn)
0
+ MOP.Class(klass).method(methodName).trace(guardFn)
0
+Replaces <code>object.methodName</code> by a method that calls the
0
+underlying function, and prints to the console the name of the method
0
+== Temporary Method Replacement
0
new MOP.MethodReplacer(object, methods)
0
- When a new MethodReplacer is constructed, it replaces each method
0
- on `object` by the method in `methods` with the same key value, if
0
- such a method exists. A MethodReplacer has a single method,
0
- `restore`, which restores each method to its pre-replacement
0
+When a new MethodReplacer is constructed, it replaces each method
0
+on +object+ by the method in +methods+ with the same key value, if
0
+such a method exists. A MethodReplacer has a single method,
0
++restore+, which restores each method to its pre-replacement
0
+ MOP.withMethodOverridesCallback(object, methods, k)
0
+Calls +fn+ on +object+, within a dynamic scope within which the
0
+methods in +methods+ have temporarily replaced the like-named
0
+methods on +object+. The scope is terminated by the argument to
0
+the call to +k+; this argument should be treated as a
0
+continuation, and restores the methods.
0
+== Method Call Serialization
0
new MOP.QueueBall(object, methodNames)
0
- When a new QueueBall is constructed, it replaces each method named
0
- by `methodNames` with a method that enqueues the method call (the
0
- name of the method and its arguments). A QueueBall has a single
0
- method, `replayMethodCalls`, which plays back the method calls and
0
- MOP.withMethodOverridesCallback(object, methods, fn)
0
- Calls `fn` on `object`, within a dynamic scope within which the
0
- methods in `methods` have temporarily replaced the like-named
0
- methods on `object`. The scope is terminated by the argument to
0
- the call to `fn`; this argument should be treated as a
0
- continuation, and restores the methods.
0
+When a new QueueBall is constructed, it replaces each method named
0
+by +methodNames+ with a method that enqueues the method call (the
0
+name of the method and its arguments). A QueueBall has a single
0
+method, +replayMethodCalls+, which plays back the method calls and
0
+ MOP.withDeferredMethods(object, methodNames, k)
0
+Calls +fn+ on +object+, within a dynamic scope within which the
0
+methods in +methodNames+ have been enqueued. The scope is
0
+terminated by the argument to the call to +k+; this argument
0
+should be treated as a continuation, and ends the queue, replaying
0
- MOP.withDeferredMethods(object, methodNames, fn)
0
- Calls `fn` on `object`, within a dynamic scope within which the
0
- methods in `methodNames` have been enqueued. The scope is
0
- terminated by the argument to the call to `fn`; this argument
0
- should be treated as a continuation, and ends the queue, replaying
0
-See the specs for examples.
0
+Download from http://github.com/osteele/mop-js, or clone from
0
+ git clone http://github.com/osteele/mop-js.git
0
-Copyright 2007-2008 by Oliver Steele. Available under the MIT License.
0
+Copyright 2007-2008 by Oliver Steele. All rights reserved.
0
+Available under the MIT License.
Comments
No one has commented yet.