Class TKClass
Object
|
+--TKClass
- class
TKClass
The TKClass function will process a constructor function and set up its inheritance chain, synthetize
a number of its instance properties and mix in additional capabilities based properties defined on
that function. The supported properties are:
inherits – the superclass
includes – an Array of modules to pull in
synthetizes – an Array of properties to synthetize
For instance, consider the following class declaration:
// extends MySuperClass
MyClass.inherits = MySuperClass;
// mixes in the TKEventTriage and TKPropertyTriage modules
MyClass.includes = [TKEventTriage, TKPropertyTriage];
// synthetizes the .foo and .bar properties
MyClass.synthetizes = ['foo', 'bar'];
function MyClass () {
// constructor code goes here
};
// process properties set up on the MyClass constructor
TKClass(MyClass);
Synthetization is fully automated as long as the class that wishes to offer synthetized properties follows
the following rules:
- say the class wishes to synthetize the property
.foo
- if the class chooses to define a getter method, it must be defined as
getFoo on its prototype
- if the class chooses to define a setter method, it must be defined as
setFoo on its prototype
- the class must define an instance variable
._foo which is the internal object that the class is responsible to update if either a setter is specified
So our previous class declaration could be extended as follows:
function MyClass () {
this._foo = '';
};
// custom setter for .foo, the getter is not specified
// and TKClass() will automatically create it
MyClass.prototype.setFoo = function (newFooValue) {
this._foo = newFooValue;
};
// custom getter for .foo, the setter is not specified
// and TKClass() will automatically create it
MyClass.prototype.getBar = function (newFooValue) {
return 'Hello ' + this._foo;
};
Defined in Class.js
|
Constructor Summary |
TKClass(theClass)
Copyright © 2009 Apple Inc.
|
|
Method Summary |
<static> void
|
mixin(target, sources)
|
<static> void
|
synthetizeProperty(object, propertyName, isPropertyInherited)
|
TKClass
TKClass(theClass)
Copyright © 2009 Apple Inc. All rights reserved.
Parameters:
theClass - {Object} The class.
mixin
<static> void mixin(target, sources)
synthetizeProperty
<static> void synthetizeProperty(object, propertyName, isPropertyInherited)
Documentation generated by
JSDoc on Tue Sep 15 21:24:36 2009