Created
December 16, 2010 04:47
-
-
Save elarkin/743045 to your computer and use it in GitHub Desktop.
.__proto__.constructor vs .constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var A = function A() {}; | |
var B = function B() {}; | |
B.prototype = new A(); | |
// B.prototype.constructor = B; // only way I can find to get bi's constructor to be B. Comment or uncomment this line to produce exactly the same output for both tests. It doesn't matter. | |
// require('util').inherits(B, A); // same here. Comment or uncomment it doesn't make a difference. | |
var ai = new A(); | |
var bi = new B(); | |
console.log('Test 1: constructor directly'); | |
console.log(ai.constructor.name); | |
console.log(bi.constructor.name); | |
console.log(''); | |
console.log('Test 2: constructor through __proto__'); | |
console.log(ai.__proto__.constructor.name); | |
console.log(bi.__proto__.constructor.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment