Inheritance and composition
The modern JavaScript with the ES6 syntax and the rise of the popularity like ReactJS, functional programming becomes more and more common. When using React, one of the common practice is to use composition instead of inheritance.
Because I started learning programming when the OOP was the most prevailing paradigm, I was trained to solve the problem by using OOP concepts like polymorphoism, inheritance, encapsulation, etc.
I think JS is the most interesting programming language in the modern technology. It supports server-side and client-side development. With the ES6, it supports OOP keywords like class and also using FP (functional programming) syntax like fat arrow (=>).
Firefox or Chromium (software development)?
I was switching from Chromium to Firefox as my primary web browser recently. Then, I switched back to Chromium again.
Chrome was usually claimed that it consumes a lot of memory. And recent Firefox updates claim that it is faster and consumes less memory. That is why, I switched to Firefox. I agree that, it is much faster than before. However…
I faced a critical issue. One less important issue that I would like to mention is, Firefox does not support Google Hangout.
Closure
In JavaScript, we can create closure like this,
[code language=“javascript”] var foo = (() => { let x = 0; return () => { return x++; } })();
for (var i = 0; i < 10; i++) { var x = foo(); console.log(x); } [/code]
But translating above code into C++, it cannot work as expected for the variable, unless the variable is outside the lambda function.
[code language=“cpp”] // In a function int x; // variable here auto foo = [&x]() { x = 0; return [&x]() { return x++; }; }(); for (int i = 0; i < 10; i++) { int x = foo(); cout « x « endl; } [/code]
JavaScript
Previously I read an article regarding JavaScript and another one regarding HTML.
JavaScript, it is so wonderful that not only enhances the HTML interaction, (e.g. jQuery), it also makes a revolution of the system architecture design (e.g. AngularJS, ReactJS with Babel). The Babel JavaScript compiler is so amazing that it can transform the JavaScript to EcmaScript 6 with JSX feature. JSX is actually cannot be interpreted by our current web browser, but with the Babel, it makes JSX possible.
TinyMCE plugin: inserttab
I wrote a small plugin for TinyMCE, to solve the “tab” problem. This is because, in the TinyMCE editor, whenever I press “tab”, it will navigate, instead of insert “\t” in the editor.
After some understanding with TinyMCE API, then I wrote this plugin.
Usage:
- Add the inserttab plugin button to the toolbar, in the HTML Javascript. This will show a button with “\t” image in the editor.
- Click the button to enable the feature.
- Then, whenever we press “tab”, if it is preformatted text, then it will become a real tab, “\t”, else will be filled with “ ”.
- To turn off, just click the button again.
The plugin is BSD license. It can be downloaded here.
My first Greasemonkey script
Finally, I wrote a Greasemonkey script. The script is target on a Chinese comic website. You can download the script here. I wrote the script because the links are not named in sequence. To offline read the comic, I would like to download the comic first. Then I can read the comic offline. After that, I can delete the comic.
But the name are not in sequence, I cannot download the comic using batch downloading. Thus, writing this script to produce the link, then from the link, I can download the comic with any download manager.