Thursday, November 11, 2010

Quicken 2004 License Renewal

Functional Inheritance in JavaScript

Functional inheritance is a term coined by Douglas Crockford.

functions are objects. How objects can also even functions properties (Properties) and methods (functions) have.

Functional Verberbung implemented it by creating a function that creates the objects and returns. Within this object-generating function, there are private instance variables. These can access the returned object as a closure. For the users of the returned object but they are invisible. The object being returned is to extend methods. These methods can also access the private variables.

  

function square (width) {
square object var = {} return;
squareObject.getArea = function () {
if (width> 0) {
width * width;}


} return square object;}


mySquare var = square (5);
print (mySquare.getArea ()) / / 25
print (mySquare.width) / / undefined


inheritance can be implemented in the functional inheritance, with the Decorator design pattern. To implement a subtype option extends the supertype to the required properties or methods. To overwrite methods to store in private variables, these can then also be used even if the methods of the super-object has been overwritten.

  

function box (width) {
boxObject var = square (width);
var = getSquareArea boxObject.getArea;
boxObject.getVolume = function () {
if (width> 0) {return
getSquareArea () * width;}

}
boxObject. getArea = function () {
if (width> 0) {return
getSquareArea () * 6;
}}

boxObject return;}


MyBox var = box (5);
print (myBox.getVolume ( )) / / 125
print (myBox.getArea ()) / / 150


This approach is probably the simplest approach for object-oriented programming in JavaScript because he does not need prototypes and constructor functions.

This is a cross-post from Ajaxer.de.

0 comments:

Post a Comment