Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FoxLANWeb : the magic fox lives on both LAN and Web!
Message
De
03/11/2010 09:09:16
 
 
À
03/11/2010 08:18:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Divers
Thread ID:
01466562
Message ID:
01487952
Vues:
131
>Far more powerful: It gives you even more possibilities, that is true. Monkeypatching (assigning functions to specific instances as "methods") allows some interesting things

As you mention, you can add methods to any object at any time.

You can event add methods to the prototype of native objects such as String, Array, and even Function.

Prototype framework uses this pattern extensively ... some dislike, we adore !

For example, as Prototype adds a 'startsWith()' method to the String prototype, any String instance created after Prototype is loaded inherits this method :
var myString = 'myString';
alert(myString.startsWith('my')); // displays 'true' in a messagebox 
> but "more OO" ? You can/have to define your own object description pattern - is that what you mean ?

I mean that everything in the language is an object : a String, an Array, and even a Function.
You are able to write every instruction in an object-oriented fashion, and even set the definition of the 'this' keyword within a function.

Prototype framework has a very handy, and famous method .bind() for that purpose (I write 'famous' because it will probably be included as native in the next version of ECMA script, AKA Javascript 2.0).
Example:
var myString = 'myString';
var myFunc = function(){alert(this);}.bind(myString); /* now the 'this' keyword within myFunc points to myString */
myFunc(); /* displays 'myString' in a messagebox */
Note : if you have fireFox with FireBug, just copy-paste the code sample above in the extended command window of the console tab while navigating on a page where Prototype is loaded, such as http://www.foxincloud.com/demos.php
Thierry Nivelet
FoxinCloud
Give your VFP application a second life, web-based, in YOUR cloud
http://foxincloud.com/
Never explain, never complain (Queen Elizabeth II)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform