I wasn't thinking of anything it could be used for, it was just an experiment :) I don't expect anyone to actually *use* it!
On 9 August 2011 23:47, Nathan Sweet <[email protected]> wrote: > That's a fun bit of trickery you've got going on. You're kind of imitating > what the native instantiation of an object is doing in the background. I can > imagine a couple of ways in which this might be useful for security reasons, > although really obscurely. What were you thinking this could be used for? > > On Tue, Aug 9, 2011 at 3:25 PM, Nick Morgan <[email protected]> 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; >> } >> >> >> -- >> 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] > > -- > 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]
