• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkTS使用JSVM-API接口进行object相关开发
2
3### 介绍
4
5使用JSVM-API接口进行object相关开发,处理JavaScript对象的基本操作的功能,例如创建对象、获取原型、冻结和密封对象,检查对象的类型等。这些操作是在处理JavaScript对象时非常常见的,提供了一种与JavaScript对象交互的方式。
6
7该工程中展示的代码详细描述可查如下链接:
8
9- [使用JSVM-API接口进行object相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-object.md)
10
11### 效果预览
12
13|                                首页                                 |                         执行及结果即时反馈                          |
14| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: |
15| <img src="./screenshots/JsvmAboutObject_1.png" style="zoom:33%;" /> | <img src="./screenshots/JsvmAboutObject_2.png" style="zoom:33%;" /> |
16
17### 使用说明
18
191. 在主界面,可以点击Hello World,开始执行。
202. 执行结果会即时反馈在屏幕中央,并在控制台打印log。
21
22### 工程目录
23
24```
25checkobjecttypetag/src/
26 ├── main
27 │   ├── cpp
28 │   │   ├── types
29 │   │   │   ├── libcheckobjecttypetag
30 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
31 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关联
32 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
33 │   │   ├── hello.cpp                   // 实现Native侧的runTest接口
34 │   ├── ets
35 │   │   ├── checkobjecttypetagability
36 │   │   ├── pages
37 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
38 │   ├── module.json5
39 │   └── resources
40 ├── ohosTest
41 │   ├── ets
42 │   │   ├── test
43 │   │       ├── Ability.test.ets        // 自动化测试代码
44createexternal/src/
45 ├── main
46 │   ├── cpp
47 │   │   ├── types
48 │   │   │   ├── libcreateexternal
49 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
50 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关联
51 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
52 │   │   ├── hello.cpp                   // 实现Native侧的runTest接口
53 │   ├── ets
54 │   │   ├── createexternalability
55 │   │   ├── pages
56 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
57 │   ├── module.json5
58 │   └── resources
59 ├── ohosTest
60 │   ├── ets
61 │   │   ├── test
62 │   │       ├── Ability.test.ets        // 自动化测试代码
63createobject/src/
64 ├── main
65 │   ├── cpp
66 │   │   ├── types
67 │   │   │   ├── libcreateobject
68 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
69 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
70 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
71 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
72 │   ├── ets
73 │   │   ├── createobjectability
74 │   │   ├── pages
75 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
76 │   ├── module.json5
77 │   └── resources
78 ├── ohosTest
79 │   ├── ets
80 │   │   ├── test
81 │   │       ├── Ability.test.ets        // 自动化测试代码
82createsymbol/src/
83 ├── main
84 │   ├── cpp
85 │   │   ├── types
86 │   │   │   ├── libcreatesymbol
87 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
88 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
89 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
90 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
91 │   ├── ets
92 │   │   ├── createsymbolability
93 │   │   ├── pages
94 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
95 │   ├── module.json5
96 │   └── resources
97 ├── ohosTest
98 │   ├── ets
99 │   │   ├── test
100 │   │       ├── Ability.test.ets        // 自动化测试代码
101getprototype/src/
102 ├── main
103 │   ├── cpp
104 │   │   ├── types
105 │   │   │   ├── libentry
106 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
107 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
108 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
109 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
110 │   ├── ets
111 │   │   ├── entryability
112 │   │   ├── entrybackupability
113 │   │   ├── pages
114 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
115 │   ├── module.json5
116 │   └── resources
117 ├── ohosTest
118 │   ├── ets
119 │   │   ├── test
120 │   │       ├── Ability.test.ets        // 自动化测试代码
121getvalueexternal/src/
122 ├── main
123 │   ├── cpp
124 │   │   ├── types
125 │   │   │   ├── libgetvalueexternal
126 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
127 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
128 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
129 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
130 │   ├── ets
131 │   │   ├── getvalueexternalability
132 │   │   ├── pages
133 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
134 │   ├── module.json5
135 │   └── resources
136 ├── ohosTest
137 │   ├── ets
138 │   │   ├── test
139 │   │       ├── Ability.test.ets        // 自动化测试代码
140instanceof/src/
141 ├── main
142 │   ├── cpp
143 │   │   ├── types
144 │   │   │   ├── libinstanceof
145 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
146 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
147 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
148 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
149 │   ├── ets
150 │   │   ├── instanceofability
151 │   │   ├── pages
152 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
153 │   ├── module.json5
154 │   └── resources
155 ├── ohosTest
156 │   ├── ets
157 │   │   ├── test
158 │   │       ├── Ability.test.ets        // 自动化测试代码
159objectfreeze/src/
160 ├── main
161 │   ├── cpp
162 │   │   ├── types
163 │   │   │   ├── libobjectfreeze
164 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
165 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
166 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
167 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
168 │   ├── ets
169 │   │   ├── objectfreezeability
170 │   │   ├── pages
171 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
172 │   ├── module.json5
173 │   └── resources
174 ├── ohosTest
175 │   ├── ets
176 │   │   ├── test
177 │   │       ├── Ability.test.ets        // 自动化测试代码
178objectseal/src/
179 ├── main
180 │   ├── cpp
181 │   │   ├── types
182 │   │   │   ├── libobjectseal
183 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
184 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
185 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
186 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
187 │   ├── ets
188 │   │   ├── objectsealability
189 │   │   ├── pages
190 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
191 │   ├── module.json5
192 │   └── resources
193 ├── ohosTest
194 │   ├── ets
195 │   │   ├── test
196 │   │       ├── Ability.test.ets        // 自动化测试代码
197symbolfor/src/
198 ├── main
199 │   ├── cpp
200 │   │   ├── types
201 │   │   │   ├── libsymbolfor
202 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
203 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
204 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
205 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
206 │   ├── ets
207 │   │   ├── symbolforability
208 │   │   ├── pages
209 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
210 │   ├── module.json5
211 │   └── resources
212 ├── ohosTest
213 │   ├── ets
214 │   │   ├── test
215 │   │       ├── Ability.test.ets        // 自动化测试代码
216typeof/src/
217 ├── main
218 │   ├── cpp
219 │   │   ├── types
220 │   │   │   ├── libtypeof
221 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
222 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
223 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
224 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
225 │   ├── ets
226 │   │   ├── typeofability
227 │   │   ├── pages
228 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
229 │   ├── module.json5
230 │   └── resources
231 ├── ohosTest
232 │   ├── ets
233 │   │   ├── test
234 │   │       ├── Ability.test.ets        // 自动化测试代码
235```
236
237### 相关权限
238
239不涉及。
240
241### 依赖
242
243不涉及。
244
245### 约束与限制
246
2471.本示例仅支持标准系统上运行, 支持设备:Phone。
248
2492.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。
250
2513.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。
252
253### 下载
254
255如需单独下载本工程,执行如下命令:
256
257```
258git init
259git config core.sparsecheckout true
260echo code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject > .git/info/sparse-checkout
261git remote add origin https://gitee.com/openharmony/applications_app_samples.git
262git pull origin master
263```
264