N-API
1 | // hello.cc using N-API |
nodejs module系统(require)
1 | //直接导出对象 引用该模块的代码不需要使用new初始化(实例化后的对象) 可以直接使用. |
export (import)
export default 为ES6新的模块系统,使用的是import导入
1 | //导出模块,常量,函数,文件等等 |
使用node-gyp编译使用N-API的cpp代码.
node-gyp使用binding.gyp作为项目的配置文件(名字是固定的)
1 | binding.gyp: |
react native
用到的工具有:reactnative,react-native-cli
使用npm install react-native-cli -g 全局安装react-native-cli脚手架工具
helloworld工程:
使用react-native init myapp //初始化app
工程结构:
├── App.js // App组件
├── HelloWorld.js //user helloworld组件 测试 jay添加的
├── RN.md // 学习笔记
├── tests //test目录
├── android // android目录
├── app.json //app.json
├── babel.config.js //babel工具配置文件
├── index.js //入口
├── ios //ios目录
├── metro.config.js
├── node_modules
├── package-lock.json
└── package.json //npm工具包配置
rn入口为index.js.rn中全是组建,在index.js中就是把组建注册???
typescript
变量声明:
1
2
3typescript提供可选类型.
var name:string = "jay";
var age:number = 18;类:
1
2
3
4
5
6
7
8
9class TS {
//属性:
name:string;
age:number;
//方法:
GetName():string{
return this.name;
}
}1
2
3
4
5- 类声明关键词:
//声明类
declare class TS{
} ;typescript 关键词
interface 和 type
1
2
3
4
5
6
7
8
9
10
11
12interface TS{
}
type TS = {
}
type Jstring = string;
type JstringOrJnum = string|number;
type Jtype = [string,number]
interface只能声明一个对象或者函数,type不仅可以声明一个对象或者函数而且还可以声明基本类型别名,联合类型,元组等类型interface 和 class
typescript中声明一个类型,我们通常会有两种做法:
- 使用class
1
2
3
4
5
6export default class state {
userInfo: {
name: string,
age: number
}
} - 使用interface:
1
2
3
4
5
6export interface STATE {
userInfo : {
name: string,
age: number
}
}由于typescript的宗旨是兼容js,运行时要擦除所有类型信息,
因此interface在运行时是会被完全消除的。
而class经过编译后,在运行时依然存
在。因此如果要声明的类型只是纯粹的类型信息,只需要声明interface即可。
}
- typescript ?:
1
2
3
4
5typescript 中 ?:表示可选
class TS{
name:string; //必选项
age?:number; //可选项
}
HTML问题
在HTML中元素使用js函数的时候要保证函数定义和使用在一个块中.
例如:
1 |
|