How to extend existing constructor function in javascript? -


Let's say I have the following object function:
  function A (option) {html> 

..}

Then I want to create a new function (B) which is the owner of the prototype of A. These are the conditions I am looking for:

  • The prototype of B, if modified, do not call the A
  • as a constructor B function Should be A Constructor of A

    B should look like this:

    Function B (aOptions, bOptions) {...}

      var b = new B ({}, {})    

    just a constructor to this

      function b (an option, bioption) {a.call (this, AOptions) Call up area. ; // do bops stuff here ...}   

    Now to set the prototype

      B.prototype = Object.create (aprototype, { Manufacturer: {value: b}}); Now B will have prototype methods from A.  

    There will be some other changes in


    prototype of A in any new way to be added to the prototype of B, which is your life Can also make it easy.

      function A (option) {// make` new` optional if (! For example A)) {return new A (option); } // do stuff with options here ...}   

    and do this for b

      function b (aOptions, bOptions) {// Make` new` optional if (! (B of this example)) Return (new B (option, bipation); } // Call parent constructor a. Cole (this, an option); // do stuff here with bOptions ...}   

    Now you can call A or New A (Option) < / Code> to get the same results.

    With B, B (aOptions, bOptions) or New B (aOptions, bOptions) will get the same result.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -