Created
November 18, 2011 04:05
-
-
Save kokudori/1375570 to your computer and use it in GitHub Desktop.
JavaScriptのプロパティ解決の擬似コード
This file contains 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
Object.prototype.send = function (name) { | |
return (function (prototype) { | |
if (!prototype) | |
return undefined; | |
if (name in prototype) | |
return prototype[name]; | |
arguments.callee(prototype.__proto__); | |
})(this); | |
}; | |
var Hoge = function () { this.aaa = 100; }; | |
Hoge.prototype.hoge = "there are a Hoge's prototype"; | |
var Piyo = function () { this.bbb = 200; }; | |
Piyo.prototype = Hoge.prototype; | |
Piyo.prototype.piyo = "there are a Piyo's prototype"; | |
var obj = new Piyo(); | |
console.log(obj.send('hoge')); | |
console.log(obj.hoge); | |
/* 実行結果 | |
there are a Hoge's prototype | |
there are a Hoge's prototype | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment