Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Code I wrote whilst angry

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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!

  2. #12
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    I sometimes do
    Trinithis

  3. #13
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Normal people punch things when they get angry!

    What on earth does it actually do?
    Programmers are tools used to convert Caffeine to code

  4. #14
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Interesting code. What ticked you off?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #15
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Interesting code. What ticked you off?
    Eh, various things.
    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!

  6. #16
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    Interesting code. What ticked you off?
    Eh, various things.
    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

  7. #17
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
    var Dom = (function() {
      var r = function(s) {
        // CSS selector stuff
      };
    
      r.byName = function(s) {
        return document.getElementsByName(s);
      };
    
      return r;
    })();
    Which allows code like:
    Code:
    var someEl         = Dom("#some-id"),
        someOtherEls   = Dom.byName("and-a-name"),
        andSomeMoreEls = Dom(".some-class");
    ... where the most useful function is more easily accessible (at the cost of being named less descriptively).
    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!

  8. #18
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    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

  9. #19
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, you'll never have a need for it. It's a convenience. Rather than:
    Code:
    function foo(arg) {
      if (typeof arg === "string") {
        bar();
      } else if (typeof arg === "number") {
        baz();
      } else {
        quux();
      }
    }
    You would:
    Code:
    var foo = Generic.create(quux);
    foo.specialise(['string'], bar);
    foo.specialise(['number'], baz);
    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.
    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!

  10. The Following User Says Thank You to Twey For This Useful Post:

    Dal (08-10-2008)

  11. #20
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •