Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.