Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how does this program work?

    Code:
    <script> 
    classa=function(array)
    {
    return new classa.prototype.init(array); 
    }
    
    classa.prototype={
    init:function(array)
    {
    return this.setArray(array);
    },
    setArray : function(elems) {    
            this.length = 0;    
            Array.prototype.push.apply(this, elems);    
            return this;    
        }
    
    }
    classa.prototype.init.prototype=classa.prototype;
    alert(classa([1,2,3])[0]);
    alert(typeof(classa([1,2,3]));
    </script>
    this program was changed from source code of "jquery",
    I don't know why classa([1,2,3]) can use like a array,
    I don't how how keywords "new" works here, what "this" point step by step,
    who can analysis this program for me ,any answer will be greatly appreciated.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Do research in OO JavaScript. Plenty of material out there that will teach you how it works.

    [1,2,3] is array notation. Any intro book to JavaScript will explain it.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Because no one cares.


  •  

    Posting Permissions

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