Skip to content

Commit c9bc996

Browse files
Update README
1 parent d258d7b commit c9bc996

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

README.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[![Platform](http://cocoapod-badges.herokuapp.com/p/JavaScriptBridge/badge.png)](http://cocoadocs.org/docsets/JavaScriptBridge)
55
[![Build Status](https://travis-ci.org/kishikawakatsumi/JavaScriptBridge.png?branch=master)](https://travis-ci.org/kishikawakatsumi/JavaScriptBridge)
66

7-
JavaScriptBridge provides the way to write iOS apps with JavaScript.
7+
Write iOS apps in Javascript! JavaScriptBridge provides the way to write iOS apps with JavaScript.
8+
JavaScriptBridge bridges Cocoa touch to JavaScriptCore (JavaScriptCore.framework is introduced in iOS 7).
89

910
## Usage
1011

@@ -26,22 +27,51 @@ JSContext *context = [JSBScriptingSupport globalContext];
2627
];
2728
```
2829

29-
### Naming conventions
30+
### Syntax/Naming conventions
3031

3132
**Class name**
3233
- Same as Objectige-C
3334

3435
**Variable declaration**
35-
- Get rid of type instead use `var`
36+
- Get rid of `Type` instead use `var`
37+
38+
*Objective-C*
39+
```objc
40+
UILabel *label;
41+
```
42+
43+
*JavaScript*
44+
```javascript
45+
var label;
46+
```
47+
48+
**Properties**
49+
- Use dot syntax
50+
51+
```objc
52+
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
53+
slider.backgroundColor = [UIColor clearColor];
54+
slider.minimumValue = 0.0;
55+
slider.maximumValue = 100.0;
56+
slider.continuous = YES;
57+
slider.value = 50.0;
58+
```
59+
60+
*JavaScript*
61+
```javascript
62+
var slider = UISlider.alloc().initWithFrame(frame);
63+
slider.backgroundColor = UIColor.clearColor();
64+
slider.minimumValue = 0.0;
65+
slider.maximumValue = 100.0;
66+
slider.continuous = true;
67+
slider.value = 50.0;
68+
```
3669

3770
**Invoking method**
3871
- Use dot syntax
3972
- All colons are removed from the selector
4073
- Any lowercase letter that had followed a colon will be capitalized
4174

42-
43-
**Example**
44-
4575
*Objective-C*
4676
```objc
4777
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
@@ -52,6 +82,27 @@ UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds
5282
var window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen().bounds);
5383
```
5484

85+
**Struct (CGRect, NSRange, etc.)**
86+
- Use Hashes
87+
88+
*Objective-C*
89+
```objc
90+
UIView *view = [UIView new];
91+
view.frame = CGRectMake(20, 80, 280, 80);
92+
93+
CGFloat x = view.frame.origin.x;
94+
CGFloat width = view.frame.size.width;
95+
```
96+
97+
*JavaScript*
98+
```javascript
99+
var view = UIView.new();
100+
view.frame = {x: 20, y: 80, width: 280, height: 80};
101+
102+
var x = view.frame.x; // => 20
103+
var width = view.frame.width; // => 280
104+
```
105+
55106
###Hello world on JavaScriptBridge
56107

57108
This is the most simple way.

0 commit comments

Comments
 (0)