Yes, definitely inspired by SICP (though I wanted to add inheritance
as well). I'm sure I'm re-implementing a lot of what JS does under the
covers - I just wanted to see if I could do it without objects. That's
interesting to know though.

The one thing that this code adds is the option to do some kind of
`method_missing` in the method definitions, which is something I miss
in JS. Though if that was the only thing I wanted to achieve, I'm sure
I could do it a lot more easily another way!

I'll look into not creating a new FE in the dispatcher.

Cheers!

Nick

On 10 August 2011 08:46, Dmitry A. Soshnikov <[email protected]> wrote:
> So you've implemented "message-passing" style objects (I guess, from SICP,
> by looking on the code). The thing is, that objects in JS exactly work by
> this technique and all this desugared variants are sugared into object
> literal notations, dot and bracket property accessors (i.e. message passing
> to objects).
>
> That's interesting for understanding this technique (in contrast with say
> "method calls" technique in static languages, when you cannot change
> dispatching routs, inheriting e.g. from several delegates). Though, you may
> want to consider not creating every time a new FE on each message acceptor
> in the dispatcher.
>
> Dmitry.
>
> On 10.08.2011 2:25, Nick Morgan wrote:
>>
>> Hi all
>>
>> Just thought I'd share something I had a little fun hacking together
>> tonight: https://github.com/skilldrick/funcobj
>>
>> I wanted to see if I could create an inheritance system in JavaScript
>> only using closures. I've not allowed object literals or the dot
>> operator, which means method lookup happens in switch statements.
>>
>> I'd be really interested to see what you guys think, and if there's
>> anything I've done that's stupid (apart from the whole project).
>>
>> This is the guts of the system:
>>
>> //methodsInitializer: a function that returns methods for the new object
>> //initArgs: initialization arguments for the methodsInitializer
>> //superObject: an optional object to inherit methods
>> function objMaker(methodsInitializer, initArgs, superObject) {
>>   var methods = apply(methodsInitializer, initArgs);
>>
>>   function dispatch(methodName, self) {
>>     self = self || dispatch; //if self given use it, otherwise use this
>> function
>>     var dispatchArguments = arguments;
>>     var method = methods(methodName);
>>     if (method) {
>>       return function () {
>>         return applyWithSelf(method, self, arguments);
>>       };
>>     }
>>     if (superObject) { //re-call with superObject (this can happen
>> recursively)
>>       return function () {
>>         //when calling super, make sure self is set to the method receiver
>>         return apply(superObject(methodName, self), arguments);
>>       }
>>     }
>>     log("Method", methodName, "not known");
>>   }
>>   return dispatch;
>> }
>>
>>
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>



-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick

Save our in-boxes! http://emailcharter.org

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to