Skip to content

Commit 3b9d01a

Browse files
Update README
1 parent ab506e8 commit 3b9d01a

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ JSContext *context = [JSBScriptingSupport globalContext];
2727
];
2828
```
2929

30-
Retrieve the `JSContext` instance from `JSBScriptingSupport`.
30+
1. Retrieve the `JSContext` instance from `JSBScriptingSupport`.
3131
The context includes a lot of system classes that has been `JSExports` adopted.
3232
```objc
3333
JSContext *context = [JSBScriptingSupport globalContext];
3434
```
3535

36-
Add `JSExports` adopted classes each framework if needed.
36+
2. Add `JSExports` adopted classes each framework if needed.
3737
By default, `Foundation`, `UIKit`, `QuartzCore` frameworks are included.
3838
```objc
3939
[context addScriptingSupport:@"MapKit"];
4040
[context addScriptingSupport:@"MessageUI"];
4141
```
4242
43-
It is ready to use, writing appliction code and evaluate in JavaScript.
43+
3. It is ready to use, writing appliction code and evaluate in JavaScript.
4444
```
4545
[context evaluateScript:
4646
@"var window = UIWindow.new();"
@@ -181,6 +181,27 @@ See the [UICatalog](https://github.com/kishikawakatsumi/JavaScriptBridge/tree/ma
181181
You can define custom class in JavaScript.
182182
It is needs to interact system provided framework.
183183
184+
`JSB.define(declaration, instanceMembers)` function defines Objective-C class in JavaScript.
185+
Pass the class declaration string to first argument.
186+
187+
Second argument is instance method definitions as hash.
188+
The hash object inclueds function object, each keys are to be used as method name.
189+
190+
**Example**
191+
192+
```javascript
193+
var MainViewController = JSB.define('MainViewController : UITableViewController', {
194+
viewDidLoad: function() { // Instance Method Definitions
195+
self.navigationItem.title = 'UICatalog';
196+
},
197+
viewWillAppear: function(animated) {
198+
self.tableView.reloadData();
199+
}
200+
});
201+
```
202+
203+
**Example**
204+
184205
```javascript
185206
var MainViewController = JSB.define('MainViewController : UITableViewController <UITableviewDataSource, UITableviewDelegate>', // Declaration
186207
// Instance Method Definitions
@@ -209,6 +230,9 @@ var MainViewController = JSB.define('MainViewController : UITableViewController
209230
###Modules
210231

211232
JavaScriptBridge provides simple module system `require/exports` funcitons, like Node.js.
233+
234+
`JSB.require(name)` function enables external module, `JSB.exports` publishes a module.
235+
212236
See [example](https://github.com/kishikawakatsumi/JavaScriptBridge/tree/master/Examples/UICatalog/UICatalog/js).
213237

214238
```javascript

0 commit comments

Comments
 (0)