Skip to content

Instantly share code, notes, and snippets.

@hirokidaichi
Created April 29, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hirokidaichi/11403157 to your computer and use it in GitHub Desktop.
Save hirokidaichi/11403157 to your computer and use it in GitHub Desktop.
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