• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Technical interviews

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Originally posted by suityou01 View Post
    Wait, I see it. () is your voodoo on the fly, shot in the arm for unreadable code, function declaration. Appvar2 is the declaration. Appvar1 is the ref, so in theory this is being injected, and the reference holds outside the function declaration.

    The constructor function pointer is also set inside the first function declaration.

    tulipty question really. To emphasise the manner of object references, there should really be some code after all this performs an operation on appvar1 that was defined on appvar2.

    IMVHO.

    I think the question is fine. It checks core understanding of basic concepts. That is if the interviewer himself does too...

    Comment


      #32
      Originally posted by suityou01 View Post
      Ok not seeing how appVar1 and appVar2 are in any way related? Can we clear this up before we deal with scope?

      Ta.
      I've spaced it out to explain each part.

      Code:
      var appVar1 = {};
      Creates a new global variable called appVar1 and initialises it as an object literal.


      Code:
      (
      We'll come back to this bit.

      Code:
      function(appVar2){
      
        appVar2.MyConstructor = function() {
          //...
        };
      }
      Create an anonymous function which takes a parameter appVar2 and adds a function MyConstructor to it.

      Code:
      )
      
      (appVar1);
      Now we close that opening bracket that I said we'd come back to. This makes the block of code a function expression instead of a function declaration. This is then immediately invoked by the following (appVar1); which passes the object literal appVar1 to the function. This all has the result of adding MyConstructor to appVar1.

      Comment


        #33
        Originally posted by Bunk View Post
        I've spaced it out to explain each part.

        Code:
        var appVar1 = {};
        Creates a new global variable called appVar1 and initialises it as an object literal.


        Code:
        (
        We'll come back to this bit.

        Code:
        function(appVar2){
        
          appVar2.MyConstructor = function() {
            //...
          };
        }
        Create an anonymous function which takes a parameter appVar2 and adds a function MyConstructor to it.

        Code:
        )
        
        (appVar1);
        Now we close that opening bracket that I said we'd come back to. This makes the block of code a function expression instead of a function declaration. This is then immediately invoked by the following (appVar1); which passes the object literal appVar1 to the function. This all has the result of adding MyConstructor to appVar1.
        Nice post Bunk. Thanks.

        I think calling a method a constructor was confusing me as constructors are special. This is agin why I think the question could be better.

        Makes sense to me, as much as slippety-sloppety loosely typed, declare anywhere voodoo code ever will.
        Knock first as I might be balancing my chakras.

        Comment


          #34
          Originally posted by suityou01 View Post
          I think calling a method a constructor was confusing me as constructors are special. This is agin why I think the question could be better.
          I believe they named the property "MyConstructor" for this very reason.

          Comment


            #35
            Originally posted by suityou01 View Post
            Nice post Bunk. Thanks.

            I think calling a method a constructor was confusing me as constructors are special. This is agin why I think the question could be better.

            Makes sense to me, as much as slippety-sloppety loosely typed, declare anywhere voodoo code ever will.
            Not in Javascript

            Code:
            function myFunction() {
              console.log('in the function');
              this.something = 'Hello';
            }
            
            myFunction();
            // Call the function
            // outputs 'in the function'
            
            var myObj = new myFunction();
            // Creates an object using the function as constructor
            
            console.log(myObj.something);
            // outputs 'Hello'

            Comment


              #36
              Originally posted by suityou01 View Post
              Makes sense to me, as much as slippety-sloppety loosely typed, declare anywhere voodoo code ever will.
              Now you can add JS to BS on your CV

              Comment


                #37
                Originally posted by barrydidit View Post
                Now you can add JS to BS on your CV
                Fairly sure he had BS on his cv already.....all versions, many years experience
                When freedom comes along, don't PISH in the water supply.....

                Comment

                Working...
                X