我想知道JavaScript对象占用的大小.
采取以下功能:
function Marks(){
this.maxMarks = 100;
}
function Student(){
this.firstName = "firstName";
this.lastName = "lastName";
this.marks = new Marks();
}
Run Code Online (Sandbox Code Playgroud)
现在我实例化student
:
var stud = new Student();
Run Code Online (Sandbox Code Playgroud)
所以我可以做类似的事情
stud.firstName = "new Firstname";
alert(stud.firstName);
stud.marks.maxMarks = 200;
Run Code Online (Sandbox Code Playgroud)
等等
现在,该stud
对象将在内存中占用一些大小.它有一些数据和更多的对象.
如何找出stud
对象占用的内存量?像sizeof()
JavaScript中的东西?如果我能在单个函数调用中找到它,那将是非常棒的sizeof(stud)
.
我已经在互联网上搜索了几个月 - 找不到它(在几个论坛中询问 - 没有回复).
我在从 web3js 传递(javascript 对象数组)到以(结构数组)作为参数的solidity 函数时遇到错误。
你可以帮帮我吗?
下面是代码和错误
// web3js code
let slctedItems = [{name:'item1', qty:2},{name:'item2', qty:3}];
contract.methods.calcItems(slctedItems).call((err, total) => {
// code
})
Run Code Online (Sandbox Code Playgroud)
//solidity code
struct Item{
string name;
uint qty;
}
function calcItems(Item[] memory _items) public view returns(uint){
//code
// return uint
}
Run Code Online (Sandbox Code Playgroud)
//solidity code
struct Item{
string name;
uint qty;
}
function calcItems(Item[] memory _items) public view returns(uint){
//code
// return uint
}
Run Code Online (Sandbox Code Playgroud)
问题的在线示例和我编写的代码。在下面的链接中:https :
//malaak-habashy.github.io/
我在 web3js github 上发现了一个问题。请参阅以下链接:https :
//github.com/ethereum/web3.js/issues/3538