Skip to content

Commit a026271

Browse files
committed
fix: #25
1 parent 5632e51 commit a026271

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

README-CN.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,28 @@ QuickJSContext context = QuickJSContext.create();
7979
context.evaluate("var a = 1 + 2;");
8080
```
8181

82-
### 支持的 Java 类型
83-
以下的 Java 类型可以直接转换到 JavaScript 中使用:
82+
### 支持的类型
83+
84+
#### 以下基础类型,Java 和 JavaScript 可以直接互转使用
8485
- `boolean`
85-
- `int`
86+
- `int`
8687
- `double`
8788
- `String`
88-
- `null`
89+
- `null`
90+
91+
#### JS 对象类型的互转
8992
- `JSObject` 代表一个 JavaScript 对象
9093
- `JSFunction` 代表一个 JavaScript 方法
9194
- `JSArray` 代表一个 JavaScript 数组
92-
95+
96+
#### 关于 Long 类型
97+
因为 JavaScript 里没有对应 Java 的 Long 类型,所以,Long 类型的转换比较特殊。
98+
- 从 Java 可以直接传 Long 值到 JavaScript,会转为 Int64 位。
99+
- 从 JavaScript 传值到 Java 转为为 Long 类型,需要借助 Double 类型,示例如下:
100+
```Java
101+
((Double)target).longValue());
102+
```
103+
93104
### 属性设置
94105
Java
95106

@@ -173,4 +184,4 @@ console.log('age:' + age); // 18
173184

174185
- [quickjs-java](https://github.com/cashapp/quickjs-java)
175186
- [quack](https://github.com/koush/quack)
176-
- [quickjs-android](https://github.com/taoweiji/quickjs-android)
187+
- [quickjs-android](https://github.com/taoweiji/quickjs-android)

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,28 @@ QuickJSContext context = QuickJSContext.create();
8282
context.evaluate("var a = 1 + 2;");
8383
```
8484

85-
### Supported Java Types
86-
Currently, the following Java types are supported with JavaScript:
85+
### Supported Types
86+
87+
#### Java and JavaScript can directly convert to each other for the following basic types
8788
- `boolean`
8889
- `int` when calling JavaScript from Java.
8990
- `double`
9091
- `String`
9192
- `null`
93+
94+
#### Mutual conversion of JS object types
9295
- `JSObject` represents a JavaScript object
9396
- `JSFunction` represents a JavaScript function
9497
- `JSArray` represents a JavaScript Array
95-
98+
99+
#### About Long Type
100+
Because there is no Long type corresponding to Java in JavaScript, the conversion of Long type is special.
101+
- Long value can be directly transferred from Java to JavaScript, which will be converted to Int64 bit。
102+
- To convert a value from JavaScript to Java into a Long type, you need to use the Double type, as shown in the following example:
103+
```Java
104+
((Double)target).longValue());
105+
```
106+
96107
### Set Property
97108
Java
98109

0 commit comments

Comments
 (0)