Thursday, 15 August 2013

jquery - How to extend javascript module which use prototype -


The specific JS file in my project is a module implemented like the following example

  Define ("Company", ["Export", "Employee"], Function (Employee) {Function Company (Name) {this.name = name; this.employees = [];}; Company.prototype AddEmployee = Function (Name) {var employee = new employee employee (name); employee employee (employee); company = this;}; export; company = company;});  

Now in the different JS file (new module) I want to expand the addemployee method, for example I want to add address data to it, is it possible is ?? ? If so, how should I do this? Example would be very useful!

Thank you in advance!

If you want to change this method only for an example that you can make your module Create a new event in company , create an override addEmployee method on your example by adding code of your code, and by calling the original method from the prototype:

  // Make a new example of the company myCompany = new company ('myCompany'); // Add the 'AddEmployee' Add method to your own way, it will override the original method / you can add more logic, if you want me to add my name to addemployee = function (name) {// your code here / / And calling the basic method settings it is for your 'example' of this, // and the company providing the proper reasoning. Prototype AddEmployee.call (this, name); }  

No comments:

Post a Comment