You're right, typeof new Function() === "function". *trim*
I didn't know you still lurked around here, Trinithis![]()
You're right, typeof new Function() === "function". *trim*
I didn't know you still lurked around here, Trinithis![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
I sometimes do![]()
Trinithis
Normal people punch things when they get angry!
What on earth does it actually do?
Programmers are tools used to convert Caffeine to code
Interesting code. What ticked you off?
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Dal: I explained it in an earlier post (the interesting bit, anyway: it also prints out various animal noises, but... no-one cares about that). Trinithis also linked to a book (an excellent book, by the way, which I highly recommend) which covers this amongst other topics.Eh, various things.Interesting code. What ticked you off?
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Was there a woman involved? I guess I deserved that short answer in trade for mine. Well you certainly haven't given us any reason here not to tick you off.
I especially liked (and I may be seeing the code wrong, so I guess I should say, "what looks to me like") the use of an anonymous function as an object in the global scope. But I will be scratching my head for awhile over exactly why. I thought that there wasn't much point in having an anonymous function other than getting all but its execution out of the global scope.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
You are indeed seeing that incorrectly, I believe. The function is called. However, there are some situations in which the pattern you describe is useful; I use it in my 'DOM' toolkit, something like this:Which allows code like:Code:var Dom = (function() { var r = function(s) { // CSS selector stuff }; r.byName = function(s) { return document.getElementsByName(s); }; return r; })();... where the most useful function is more easily accessible (at the cost of being named less descriptively).Code:var someEl = Dom("#some-id"), someOtherEls = Dom.byName("and-a-name"), andSomeMoreEls = Dom(".some-class");
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Fantastic stuff, Im sure I may even use this one day but I have no need for it at the moment. Im a noob at javascript, only 4 months experience. Thanks to C/C++ Im doing fine but functions like even the one above is a little too OOP for getting things done.
![]()
Programmers are tools used to convert Caffeine to code
Well, you'll never have a need for it. It's a convenience. Rather than:You would:Code:function foo(arg) { if (typeof arg === "string") { bar(); } else if (typeof arg === "number") { baz(); } else { quux(); } }It's particularly interesting because it's a convenience that can be used to implement a form of object orientation that's much more powerful than Java's or C++'s.Code:var foo = Generic.create(quux); foo.specialise(['string'], bar); foo.specialise(['number'], baz);
Last edited by Twey; 10-16-2008 at 02:52 AM. Reason: Can be simpler.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Dal (08-10-2008)
I suppose theres only one question remaining in that case;
What can you come up with when your happy?
Thanks for the reply Twey![]()
Programmers are tools used to convert Caffeine to code
Bookmarks