using Call to inherit objects from a function












0















I was doing some testing and I got no clue why if using call I inherit from another object like, const objC = funcB.call(objA,'Erades') I got an object, but if I inherit from a function I got a function with wired (to me) behavior.



I don't understand why to get method B I have to do funcC.getLastName()



If anybody can help me to understand this...



TIA






// testing Call to inherit objects / functions
// -------------------------------------------

// we declare our first function
const funcA = function(firstName) {
this.firstName = firstName;
this.getFirstName = function() {
return 'My name is ' + this.firstName;
};
return this;
};
// Create an object out of that function
const objA = new funcA('Rodrigo');

// declare second function
const funcB = function (lastName) {
this.lastName = lastName;
this.getLastName = function() {
return 'My last name is ' + this.lastName;
};
return this;
};

// Create an Object from funcB and ObjectA
const objC = funcB.call(objA,'Erades');
// We get an object
console.log("TYPE OF: ", typeof objC)
console.log('raw:', objC);
console.log('method A: ', objC.getFirstName());
console.log('prop A: ', objC.firstName);
console.log('method B: ', objC.getLastName());
console.log('prop B: ', objC.lastName);
console.log('------------');

// if we don't want to create an object out of a function and an object,
// we could also inherit two functions, but the result really surprise me
const funcC = funcB.call(funcA,'Alonso');
// We get a function !!!!!
console.log("TYPE OF: ", typeof funcC);
console.log('raw:', funcC);
// To get result we need to do this:
console.log('method ==>: ', funcC('Rui'));
console.log('method A: ', funcC('Rui').getFirstName());
console.log('prop A: ', funcC('Maria').firstName);
console.log('method B: ', funcC.getLastName()); // looks like static method ???
console.log('prop B: ', funcC.lastName);
console.log('------------');












share|improve this question





























    0















    I was doing some testing and I got no clue why if using call I inherit from another object like, const objC = funcB.call(objA,'Erades') I got an object, but if I inherit from a function I got a function with wired (to me) behavior.



    I don't understand why to get method B I have to do funcC.getLastName()



    If anybody can help me to understand this...



    TIA






    // testing Call to inherit objects / functions
    // -------------------------------------------

    // we declare our first function
    const funcA = function(firstName) {
    this.firstName = firstName;
    this.getFirstName = function() {
    return 'My name is ' + this.firstName;
    };
    return this;
    };
    // Create an object out of that function
    const objA = new funcA('Rodrigo');

    // declare second function
    const funcB = function (lastName) {
    this.lastName = lastName;
    this.getLastName = function() {
    return 'My last name is ' + this.lastName;
    };
    return this;
    };

    // Create an Object from funcB and ObjectA
    const objC = funcB.call(objA,'Erades');
    // We get an object
    console.log("TYPE OF: ", typeof objC)
    console.log('raw:', objC);
    console.log('method A: ', objC.getFirstName());
    console.log('prop A: ', objC.firstName);
    console.log('method B: ', objC.getLastName());
    console.log('prop B: ', objC.lastName);
    console.log('------------');

    // if we don't want to create an object out of a function and an object,
    // we could also inherit two functions, but the result really surprise me
    const funcC = funcB.call(funcA,'Alonso');
    // We get a function !!!!!
    console.log("TYPE OF: ", typeof funcC);
    console.log('raw:', funcC);
    // To get result we need to do this:
    console.log('method ==>: ', funcC('Rui'));
    console.log('method A: ', funcC('Rui').getFirstName());
    console.log('prop A: ', funcC('Maria').firstName);
    console.log('method B: ', funcC.getLastName()); // looks like static method ???
    console.log('prop B: ', funcC.lastName);
    console.log('------------');












    share|improve this question



























      0












      0








      0








      I was doing some testing and I got no clue why if using call I inherit from another object like, const objC = funcB.call(objA,'Erades') I got an object, but if I inherit from a function I got a function with wired (to me) behavior.



      I don't understand why to get method B I have to do funcC.getLastName()



      If anybody can help me to understand this...



      TIA






      // testing Call to inherit objects / functions
      // -------------------------------------------

      // we declare our first function
      const funcA = function(firstName) {
      this.firstName = firstName;
      this.getFirstName = function() {
      return 'My name is ' + this.firstName;
      };
      return this;
      };
      // Create an object out of that function
      const objA = new funcA('Rodrigo');

      // declare second function
      const funcB = function (lastName) {
      this.lastName = lastName;
      this.getLastName = function() {
      return 'My last name is ' + this.lastName;
      };
      return this;
      };

      // Create an Object from funcB and ObjectA
      const objC = funcB.call(objA,'Erades');
      // We get an object
      console.log("TYPE OF: ", typeof objC)
      console.log('raw:', objC);
      console.log('method A: ', objC.getFirstName());
      console.log('prop A: ', objC.firstName);
      console.log('method B: ', objC.getLastName());
      console.log('prop B: ', objC.lastName);
      console.log('------------');

      // if we don't want to create an object out of a function and an object,
      // we could also inherit two functions, but the result really surprise me
      const funcC = funcB.call(funcA,'Alonso');
      // We get a function !!!!!
      console.log("TYPE OF: ", typeof funcC);
      console.log('raw:', funcC);
      // To get result we need to do this:
      console.log('method ==>: ', funcC('Rui'));
      console.log('method A: ', funcC('Rui').getFirstName());
      console.log('prop A: ', funcC('Maria').firstName);
      console.log('method B: ', funcC.getLastName()); // looks like static method ???
      console.log('prop B: ', funcC.lastName);
      console.log('------------');












      share|improve this question
















      I was doing some testing and I got no clue why if using call I inherit from another object like, const objC = funcB.call(objA,'Erades') I got an object, but if I inherit from a function I got a function with wired (to me) behavior.



      I don't understand why to get method B I have to do funcC.getLastName()



      If anybody can help me to understand this...



      TIA






      // testing Call to inherit objects / functions
      // -------------------------------------------

      // we declare our first function
      const funcA = function(firstName) {
      this.firstName = firstName;
      this.getFirstName = function() {
      return 'My name is ' + this.firstName;
      };
      return this;
      };
      // Create an object out of that function
      const objA = new funcA('Rodrigo');

      // declare second function
      const funcB = function (lastName) {
      this.lastName = lastName;
      this.getLastName = function() {
      return 'My last name is ' + this.lastName;
      };
      return this;
      };

      // Create an Object from funcB and ObjectA
      const objC = funcB.call(objA,'Erades');
      // We get an object
      console.log("TYPE OF: ", typeof objC)
      console.log('raw:', objC);
      console.log('method A: ', objC.getFirstName());
      console.log('prop A: ', objC.firstName);
      console.log('method B: ', objC.getLastName());
      console.log('prop B: ', objC.lastName);
      console.log('------------');

      // if we don't want to create an object out of a function and an object,
      // we could also inherit two functions, but the result really surprise me
      const funcC = funcB.call(funcA,'Alonso');
      // We get a function !!!!!
      console.log("TYPE OF: ", typeof funcC);
      console.log('raw:', funcC);
      // To get result we need to do this:
      console.log('method ==>: ', funcC('Rui'));
      console.log('method A: ', funcC('Rui').getFirstName());
      console.log('prop A: ', funcC('Maria').firstName);
      console.log('method B: ', funcC.getLastName()); // looks like static method ???
      console.log('prop B: ', funcC.lastName);
      console.log('------------');








      // testing Call to inherit objects / functions
      // -------------------------------------------

      // we declare our first function
      const funcA = function(firstName) {
      this.firstName = firstName;
      this.getFirstName = function() {
      return 'My name is ' + this.firstName;
      };
      return this;
      };
      // Create an object out of that function
      const objA = new funcA('Rodrigo');

      // declare second function
      const funcB = function (lastName) {
      this.lastName = lastName;
      this.getLastName = function() {
      return 'My last name is ' + this.lastName;
      };
      return this;
      };

      // Create an Object from funcB and ObjectA
      const objC = funcB.call(objA,'Erades');
      // We get an object
      console.log("TYPE OF: ", typeof objC)
      console.log('raw:', objC);
      console.log('method A: ', objC.getFirstName());
      console.log('prop A: ', objC.firstName);
      console.log('method B: ', objC.getLastName());
      console.log('prop B: ', objC.lastName);
      console.log('------------');

      // if we don't want to create an object out of a function and an object,
      // we could also inherit two functions, but the result really surprise me
      const funcC = funcB.call(funcA,'Alonso');
      // We get a function !!!!!
      console.log("TYPE OF: ", typeof funcC);
      console.log('raw:', funcC);
      // To get result we need to do this:
      console.log('method ==>: ', funcC('Rui'));
      console.log('method A: ', funcC('Rui').getFirstName());
      console.log('prop A: ', funcC('Maria').firstName);
      console.log('method B: ', funcC.getLastName()); // looks like static method ???
      console.log('prop B: ', funcC.lastName);
      console.log('------------');





      // testing Call to inherit objects / functions
      // -------------------------------------------

      // we declare our first function
      const funcA = function(firstName) {
      this.firstName = firstName;
      this.getFirstName = function() {
      return 'My name is ' + this.firstName;
      };
      return this;
      };
      // Create an object out of that function
      const objA = new funcA('Rodrigo');

      // declare second function
      const funcB = function (lastName) {
      this.lastName = lastName;
      this.getLastName = function() {
      return 'My last name is ' + this.lastName;
      };
      return this;
      };

      // Create an Object from funcB and ObjectA
      const objC = funcB.call(objA,'Erades');
      // We get an object
      console.log("TYPE OF: ", typeof objC)
      console.log('raw:', objC);
      console.log('method A: ', objC.getFirstName());
      console.log('prop A: ', objC.firstName);
      console.log('method B: ', objC.getLastName());
      console.log('prop B: ', objC.lastName);
      console.log('------------');

      // if we don't want to create an object out of a function and an object,
      // we could also inherit two functions, but the result really surprise me
      const funcC = funcB.call(funcA,'Alonso');
      // We get a function !!!!!
      console.log("TYPE OF: ", typeof funcC);
      console.log('raw:', funcC);
      // To get result we need to do this:
      console.log('method ==>: ', funcC('Rui'));
      console.log('method A: ', funcC('Rui').getFirstName());
      console.log('prop A: ', funcC('Maria').firstName);
      console.log('method B: ', funcC.getLastName()); // looks like static method ???
      console.log('prop B: ', funcC.lastName);
      console.log('------------');






      javascript inheritance prototype call apply






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 6:52







      Boogie

















      asked Nov 21 '18 at 5:59









      BoogieBoogie

      356




      356
























          1 Answer
          1






          active

          oldest

          votes


















          2














          You're not inheriting when you use call this way. You are passing an instance in and getting the same instance out with some modifications:






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          When you use call the object passed in becomes the this of the function. You then add some properties and return this which is the same object you just passed in.



          Passing a function to call() is no different. When you write:



          funcB.call(funcA,'Alonso');


          you are calling the function funcB with Alonso as an argument. Inside that function this will refer to funcA. So you will set a lastName property on funcA and getLastName property pointing to a function, then return funcA which is then assigned to the variable funcC. funcC and funcA point to exactly the same function.






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)








          share|improve this answer


























          • I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

            – Boogie
            Nov 21 '18 at 7:12













          • @Boogie see edited answer. It's not really different with the functions. funcC is funcA

            – Mark Meyer
            Nov 21 '18 at 8:08













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406070%2fusing-call-to-inherit-objects-from-a-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You're not inheriting when you use call this way. You are passing an instance in and getting the same instance out with some modifications:






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          When you use call the object passed in becomes the this of the function. You then add some properties and return this which is the same object you just passed in.



          Passing a function to call() is no different. When you write:



          funcB.call(funcA,'Alonso');


          you are calling the function funcB with Alonso as an argument. Inside that function this will refer to funcA. So you will set a lastName property on funcA and getLastName property pointing to a function, then return funcA which is then assigned to the variable funcC. funcC and funcA point to exactly the same function.






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)








          share|improve this answer


























          • I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

            – Boogie
            Nov 21 '18 at 7:12













          • @Boogie see edited answer. It's not really different with the functions. funcC is funcA

            – Mark Meyer
            Nov 21 '18 at 8:08


















          2














          You're not inheriting when you use call this way. You are passing an instance in and getting the same instance out with some modifications:






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          When you use call the object passed in becomes the this of the function. You then add some properties and return this which is the same object you just passed in.



          Passing a function to call() is no different. When you write:



          funcB.call(funcA,'Alonso');


          you are calling the function funcB with Alonso as an argument. Inside that function this will refer to funcA. So you will set a lastName property on funcA and getLastName property pointing to a function, then return funcA which is then assigned to the variable funcC. funcC and funcA point to exactly the same function.






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)








          share|improve this answer


























          • I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

            – Boogie
            Nov 21 '18 at 7:12













          • @Boogie see edited answer. It's not really different with the functions. funcC is funcA

            – Mark Meyer
            Nov 21 '18 at 8:08
















          2












          2








          2







          You're not inheriting when you use call this way. You are passing an instance in and getting the same instance out with some modifications:






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          When you use call the object passed in becomes the this of the function. You then add some properties and return this which is the same object you just passed in.



          Passing a function to call() is no different. When you write:



          funcB.call(funcA,'Alonso');


          you are calling the function funcB with Alonso as an argument. Inside that function this will refer to funcA. So you will set a lastName property on funcA and getLastName property pointing to a function, then return funcA which is then assigned to the variable funcC. funcC and funcA point to exactly the same function.






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)








          share|improve this answer















          You're not inheriting when you use call this way. You are passing an instance in and getting the same instance out with some modifications:






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          When you use call the object passed in becomes the this of the function. You then add some properties and return this which is the same object you just passed in.



          Passing a function to call() is no different. When you write:



          funcB.call(funcA,'Alonso');


          you are calling the function funcB with Alonso as an argument. Inside that function this will refer to funcA. So you will set a lastName property on funcA and getLastName property pointing to a function, then return funcA which is then assigned to the variable funcC. funcC and funcA point to exactly the same function.






          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)








          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };
          const objA = new funcA('Rodrigo');

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };

          const objC = funcB.call(objA,'Erades');
          // ObjC IS ObjaA
          console.log(objC === objA)





          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)





          const funcA = function(firstName) {
          this.firstName = firstName;
          this.getFirstName = function() {
          return 'My name is ' + this.firstName;
          };
          return this;
          };

          const funcB = function (lastName) {
          this.lastName = lastName;
          this.getLastName = function() {
          return 'My last name is ' + this.lastName;
          };
          return this;
          };


          const funcC = funcB.call(funcA,'Alonso');
          // the same reference
          console.log(funcC === funcA)
          // but when you called funcB with it, it added some properties:
          console.log("funC lastname:", funcC.lastName)
          // they are the same object so this also works:
          console.log("also funcA lastname:", funcC.lastName)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 16:59

























          answered Nov 21 '18 at 6:13









          Mark MeyerMark Meyer

          38.6k33159




          38.6k33159













          • I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

            – Boogie
            Nov 21 '18 at 7:12













          • @Boogie see edited answer. It's not really different with the functions. funcC is funcA

            – Mark Meyer
            Nov 21 '18 at 8:08





















          • I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

            – Boogie
            Nov 21 '18 at 7:12













          • @Boogie see edited answer. It's not really different with the functions. funcC is funcA

            – Mark Meyer
            Nov 21 '18 at 8:08



















          I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

          – Boogie
          Nov 21 '18 at 7:12







          I see, thanks I had a misconception :), but I stil try to understand the second case when we call a function and pass another function. Does function A has a reference to function B ? If you look at the output of console.log('raw:', funcC) I can't see any reference to function B, but then if I do funcC('Rui') ---> I can access to function A.

          – Boogie
          Nov 21 '18 at 7:12















          @Boogie see edited answer. It's not really different with the functions. funcC is funcA

          – Mark Meyer
          Nov 21 '18 at 8:08







          @Boogie see edited answer. It's not really different with the functions. funcC is funcA

          – Mark Meyer
          Nov 21 '18 at 8:08






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406070%2fusing-call-to-inherit-objects-from-a-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga