Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 36

Thread: [DHTML] ActiveX Simplified

  1. #21
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I intended this.x and this.y ect so that you could do the following

    var conversion1=new $ToAscii('00000000'); - returns \n
    var conversion2=new $ToAscii('01010000'); - returns P

    then later if you needed the result back without reconverting you could do

    conversion1.tobin - would equal \n
    conversion2.tobin - would equal P

    Now that I look at it though it was stupid in this case seeing how the function returns the result to a variable anyways.

    I also wanted to prevent variable conflicts.


    Also to trinithis
    I would like to ask premission to use your conversion functions to replace my own. Yours are much more efficient.

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

    Default

    Mine are more efficient still. Have a look at the code at the bottom of my last post.

    My comment on using $ in identifiers stands, by the way. ECMA-262, section 7.6, second paragraph, states:
    The dollar sign is intended for use only in mechanically generated code.
    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!

  3. #23
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I used the dollar sign to prevent duplicate functions. I intended people to link the script and start using it. I wanted to make sure my functions and there functions were unique and short so I added the $. If you know of another valid symbol let me know.

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

    Default

    The best way of doing it is to use a namespacing object:
    Code:
    var ActiveXFunctions = {
      frontPad : function(s, len, chr) {
        for(var r = s.toString(); r.length < len; r = (chr || "0") + r);
        return r;
      },
    
      group : function(arr, len) {
        for(var i = 0, r = [], n = arr.length; i < n; ++i) {
          if(i &#37; len === 0)
            r.push([]);
          r[r.length - 1].push(arr[i]);
        }
        return r;
      },
    
      strToBin : function(str, charsiz) {
        for(var i = 0, r = "", n = str.length; i < n; r += this.frontPad(str.charCodeAt(i++).toString(2), charsiz || 8));
        return r;
      },
    
      binToStr : function(bin, charsiz) {
        for(var i = 0, cs = this.group(bin.split(""), charsiz || 8), n = cs.length; i < n; cs[i] = String.fromCharCode(parseInt(cs[i++].join(""), 2)));
        return cs.join("");
      }
    };
    Then call them:
    Code:
    var bin = ActiveXFunctions.strToBin("Hello");
    var str = ActiveXFunctions.binToStr(bin);
    Last edited by Twey; 07-18-2007 at 05:42 PM. Reason: Minor tweak... i++ is much nicer than looping from -1 to n - 1.
    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!

  5. #25
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I'm unfamiliar with your code so could you create the namespace using my code as an example without the $ signs

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

    Default

    Feel free to use it if you want, but Twey's is indeed better.
    Trinithis

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

    Default

    I'm unfamiliar with your code
    It's just object literal syntax.
    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. #28
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks I'll start using that in my scripts instead of the this.variable.

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

    Default

    They both have their places. this.varname is used when you want to create a constructor function. Object literal notation only creates a single object: perfect for namespaces.
    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. #30
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default [UPDATED VERSION] my_script.js

    No longer contains $ in function names.
    New Binary and Ascii Conversion by Twey. - Credited in file too

    Added Custom Error handler
    Added Window Resizing

    Although some of the functions do not relate to the ActiveX Objects they are useful when creating a .hta

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
  •