Posts

Showing posts with the label emulation

A Pascal record via JavaScript

... all right, I am off for holidays and I won't have probably time to write the post I have twitted a few days ago since it could take a whole day ... however, I am "cleaning" my good old room here in Italy and I have found an Italian book titled "ALGORITMI IN PASCAL" (Pascal Algorithms) a back in 1987 IT book for secondary school. I could not resist to read it entirely, just to see what kind of Algo I could have found there ... but "surprise", it was not about algos, more about (T)Pascal itself. Since at the of the day Pascal is somehow the basis for all we can write today, I thought it would have been a nice experiment to try to reproduce the record concept via JavaScript. What Is a Record Nothing different from a predefined structure of types, similar to a classic literal object in JS except the structure defines type hints. // simple Pascal function example function personToString(self:person); begin writeln(self.name, ' is ', self....

JavaScript prototype behaviour with PHP

One cool thing of JavaScript prototype model, is that you can change dynamically one or more method updating automatically every instance of that constructor. Even if classic inheritance and OO Programmers hate this feature, it could be really useful in some case. Another interesting thing, is that thanks to injected scope, you can share a prototype or use one of its defined methods, with every kind of instance. PHP is (still) dynamically limited The concept of injected scope, is absolutely extraneous to PHP developers. Even with a massive usage of Reflection API , it is not possible to use a method of class A with another class B , even if this method contains common usable tasks for both classes. At the same time, it is not possible to use a function as property, because it is not recognized as function, if called directly, and it cannot contain a $this referer, thanks to engine limitation. The light comes from PECL The official repository for PHP extensions, contains a truly inte...