How to define the prototype of an object in a constructor in JavaScript? -
I want to add object constructor as a property with an object, and add methods in the prototype of that object I am
Defining this does not work because the object is virtually running from one object and not from the manufacturer:
function processing (option) {this.self = this; This.options = Options || {}; .. other options. ... // service object that I want to add to my prototype this task. Service = {Request: New XMLHttpRequest (), requestMethod: options.requestMethod || 'GET',}, // Prototype actually creates an object that prototype // becomes the property of the service object. This.service.prototype = {dataToNode: function (element, origin, data) {var toAppend = document.createElement (element); ToAppend.innerHTML = Data; Return Parents .appendChild (toAppend); },} This works by cutting and using __proto __ to follow, but __proto___ Gets lost. I __proto __ ? How can I add object to prototype without using function resource (option) {this.self = this; This.options = Options || {}; .. other options. ... / / service object that I want to add a request to my prototype this.service = {request: new XMLHttpRequest ()): request.method: options.requestMethod || Works using 'GET',}, // __proto__, but its deprciated .service .__ proto__ = {dataToNode: function (element, parent, data) {var toAppend = document.createElement (element); ToAppend.innerHTML = Data; Return Parents .appendChild (toAppend); },}
function service (option) {this.request = new XMLHttpRequest (); this.request Method = options.requestMethod || 'get'; } Service.prototype.dataToNode = function (element, parent, data) {var toAppend = document.createElement (element); ToAppend.innerHTML = Data; Return Parents .appendChild (toAppend); }; Function processing (options) {this.options = options || {}; This.service = new service (this.options); }
Comments
Post a Comment