javascript - 将 dword 类型实现为 Javascript 数组的子类?
问题描述
我需要实现扩展精度布尔二进制算术,我想我可以使用类来为 DWORD 和“MULTIWORD”创建类型。
这样做有什么问题吗?似乎正在工作。
PS 我宁愿留在 ES5 (pre class ) 范式内。
// not production code
var DoubleWord = JSClass.Extends(Array, function(initx) {
DoubleWord.baseConstructor.call(this, initx);
// offset naught padding
var initoffset = 0;
this.s = 32; // (s)ize in bits
if (initx)
for (var i = 0; i < initx.length; i++)
this.push(initx[i]);
initoffset = this.length; // pointless, descriptional
for (var i = initoffset; i < this.s; i++)
this.push(0);
});
(忽略这
这里是 JSClass.Extends 继承实现JSClass
件事)
JSClass = {};
JSClass.Extends = function(baseClass, constructor) {
Inheritance = function() {};
Inheritance.prototype = baseClass.prototype;
constructor.prototype = new Inheritance();
constructor.prototype.constructor = constructor;
constructor.baseConstructor = baseClass;
constructor.superClass = baseClass.prototype;
return constructor;
};
解决方案
推荐阅读
- react-native - 文本字符串必须在
普通文本组件上的组件错误 - python-3.x - 日期卡在熊猫数据框中无法格式化
- regex - 如何使用 Regex 搜索和过滤对象数组?
- react-native - ReactNative - 仅在身份验证后显示 API 内容
- c - 从编译的程序中删除 ASDF 依赖项
- python - 对应时迭代数据框和格式化日期
- assembly - 汇编-使用 leaq 的这段代码的输出是什么
- apache - 如果目录不存在,htaccess 会显示“未找到”
- r - 在 R 中使用 gsub 和 grepl 的正则表达式:查找 ',' 后面没有空格
- javascript - 阻止图像上下文菜单在 Firefox 和 iOS 中打开不起作用