Posts

Showing posts with the label JavaScript Prototype

Donate

JavaScript Object Oriented Programming Using Prototype

Hello, In JavaScript, each Object can inherit properties from another object, called it's prototype . When evaluating an expression to retrieve a property, JavaScript first looks to see if the property is defined directly in the object. If it is not, it then looks at the object's prototype to see if the property is defined there. This continues up the prototype chain until reaching the root prototype. Each object is associated with a prototype which comes from the constructor function from which it is created. (Source: http://mckoss.com/jscript/object.htm ) Here's an example i created: <html> <head> <script type= "text/javascript" language= "javascript" > function NumberManip() { var result = 0; } NumberManip.prototype.add = function (num1, num2) { this .result = num1 + num2; } NumberManip.prototype.subtract = function (num1, num2) { this .result = num1 - num2; }

Donate