Created
April 29, 2014 15:08
-
-
Save hirokidaichi/11403157 to your computer and use it in GitHub Desktop.
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 DISPATCH_TABLE = {}; | |
DISPATCH_TABLE.Person = { | |
intro : function(_self){ | |
return "I am just a Person,and my name is "+_self.name; | |
} | |
}; | |
var me = { | |
_class_ : 'Person', | |
name : 'daichi hiroki', | |
qge : 30, | |
study : "computer science" | |
}; | |
function sendMessage(object,message,args){ | |
var method = DISPATCH_TABLE[object._class_][message]; | |
return method( object ,args ); | |
} | |
/* | |
Work3-1 | |
// class Child < Parent end | |
function extend(childName,parentName) { | |
} | |
Work3-2 | |
// class Child | |
// include Module | |
// end | |
function include(targetClassName,moduleName){ | |
} | |
Work3-3 | |
// class Child | |
// prepend Module | |
// end | |
function prepend(targetClassName,moduleName){ | |
} | |
Work3-4 | |
// class << object | |
// | |
// end | |
function singleton(object,dispatchTable){ | |
} | |
Work3-5 | |
implement method_missing | |
sendMessage(me,'no_such_a_method') => NoSuchAMethod | |
Work3-6 | |
implement double dispatch | |
DISPATCH_TABLE['ClassA']['ClassB'].collide = function(){} | |
sendMessage([me,you],'collide') | |
*/ | |
console.log(sendMessage(me,'intro')); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment