@ protobufjs/ 编码源
最小化代码生成工具 .
API 密码
-
代码( [函数] 参数 :
string[][功能名称:字符串]:Codegen
开始生成函数 . -
代码源.动词=
false
当设定为真时, 代码源会日志生成的代码到控制台 。 用于调试 .
引用 代码 返回将代码附加到函数正文并返回自身的附件函数:
-
代码( 格式串:
string,[.格式Params:any[ ]: 代码
附加函数正文的代码. 格式字符串可以包含指定所插入格式参数类型的占位符 :%d: 数字(整数或浮动点值)%f: 浮点值%i: 整数%j: JSON. 刻出"定值"%s: 字符串值%%: 百分比符号
-
代码( [范围 :
Object.<string,*>[ ]:Function
完成函数并返回. -
Codegen.to String( [函数] 名称 :
string[ ]:string
返回函数为字符串.
示例
var codegen = require("@protobufjs/codegen");
var add = codegen(["a", "b"], "add") // A function with parameters "a" and "b" named "add"
("// awesome comment") // adds the line to the function's body
("return a + b - c + %d", 1) // replaces %d with 1 and adds the line to the body
({ c: 1 }); // adds "c" with a value of 1 to the function's scope
console.log(add.toString()); // function add(a, b) { return a + b - c + 1 }
console.log(add(1, 2)); // calculates 1 + 2 - 1 + 1 = 3
许可证 : BSD 3- 标签许可证