答案 0 :(得分:1)
[memtest]> cargo run
Compiling memtest v0.1.0 (file:///home/icarruthers/memtest)
Finished dev [unoptimized + debuginfo] target(s) in 0.28s
Running `target/debug/memtest`
[memtest]> valgrind target/debug/memtest
==18808== Memcheck, a memory error detector
==18808== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18808== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==18808== Command: target/debug/memtest
==18808==
==18808==
==18808== HEAP SUMMARY:
==18808== in use at exit: 0 bytes in 0 blocks
==18808== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==18808==
==18808== All heap blocks were freed -- no leaks are possible
==18808==
==18808== For counts of detected and suppressed errors, rerun with: -v
==18808== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
是指对象的直接原型祖先。举一个简单的例子,__proto__
是obj
的直接祖先:
obj2
在您的图表中,它显示了从函数到let obj = {}
// make obj2 with obj parent
let obj2 = Object.create(obj)
obj === obj2.__proto__ // true
到Function.prototype
的原型链。您可以像链条一样跟随它:
Object.prototype
在您的示例中,function test(){}
console.log(test.__proto__ === Function.prototype)
console.log(test.__proto__.__proto__ === Object.prototype)
// alternatively:
Object.getPrototypeOf(test) // Function.prototype
是Object.__proto__
,因为Function.prototype
是构造函数,而Object
和String
是函数。但这与Number
不同,后者是另一个对象的Object.prototype
属性指向的对象:
__proto__