However, the real reason React is a good choice is not performance, but rather how it encourages developers to think about, isolate and better manage mutable state in their applications.
4,836 karma · joined February 6, 2010
However, the real reason React is a good choice is not performance, but rather how it encourages developers to think about, isolate and better manage mutable state in their applications.
ActiveX
Java Applets
Flash
Silverlight
VBScript (and other non-JS scripting langs)
NaCL
Dart (via a native VM)For example
function($n) use ($partial) { return $partial($n - 1) + $partial($n - 2);
could become 'partial(n - 1) + partial(n - 2)'
Compiling the string lambda to a function can be memoized with the string itself as the key (as many regex implementations do with the regex text) so each is only ever compiled once.Now that React has had a large recent influx of new users, hopefully these key concepts are not lost in the deluge of new blog posts and demo applications. Those who are championing React within groups and organisations should try to make sure developers who are more passively following are made aware of such useful ideas. Javascript (and software engineering in general) has a long history of collectively forgetting important ideas only to rediscover them later, but it would be better to be proactive than to leave it up to the archeologists.
[1] http://swannodette.github.io/2013/12/17/the-future-of-javasc...
The top two items are two instances of an imitation of a Roland TB-303 bassline synth. The bottom item is an imitation of a Roland TR-909 drum machine (a drum synthesizer).
Press 'Play' in the top left to start all three instruments playing. Each is now running through 4 bars of 4 beats, or 16 steps in total. By default the first bass synth is playing a low 'C' on every step, the second bass synth is playing nothing, and the drum machine is playing a bass drum on the first step of each bar (steps 1, 5, 9, and 13).
Laying out a pattern on the drum machine is a little more intuitive, so start with that. The row of 16 buttons represents the steps on which a hit will be played for the currently selected drum type. Buttons for switching modes to edit the pattern for each drum type are listed horizontally (BD, SD etc). Switch to a different drum and add some hits to the pattern by clicking on those steps in the row of 16 buttons.
The bassline synths are programmed in basically the opposite way. The 16 steps become the modes you switch between (by clicking the UP and DN buttons under 'Current Step') and clicking on any of the the 13 musical note buttons (coloured like piano keys) will select the note which plays on that step. The highlighted note can also be deselected so that no note will be played for that step. Try stepping through and changing the notes which are played on each step or deselecting notes to create a more interesting rhythmic pattern.
- to use Postgres JSON columns for storing documents (rather than the typical CMS approach of a complex EAV/table-per-field structure), and
- to use React components for rendering the public-facing content views, which could then also be used for inline editing or a live split preview/editor – like a markdown editor, but capable of turning arbitrary fields of input into arbitrary output
- embeddable content types/entities which know how to render themselves
- live collaborative editing
// assuming in each case
var o = {}
var o2 = {}
var fn = function(){}
// 1. bare function call
fn() // this == undefined in strict mode, global in non strict mode.
// 2. calling with Function.prototype.call
fn.call(o) // this == o
// 3. 'method' call (calling an object's function property)
o2.fn = fn
o2.fn() // this == o2
// equivalent to
fn.call(o2)
// 4. calling object's function property with Function.prototype.call
o2.fn = fn
o2.fn.call(o) // this == o
// 5. new
var o3 = new fn() // this = o3
// equivalent to
var o3 = Object.create(fn.prototype)
fn.call(o3)
// 6. calling function bound with Function.prototype.bind
var fn2 = fn.bind(o)
fn2() // this == o
// equivalent to
var fn2 = function(){ fn.call(o) }
fn2()
// 7. calling object function property which is a bound function
o2.fn = fn.bind(o)
o2.fn() // this == o
// equivalent to
o2.fn = function(){ fn.call(o) }
o2.fn()
Basically you should think of functions (and 'methods') as not being intrinsically bound (as in binding-of-'this' bound) to anything.If you think of a 'method' (function property) as being bound an object purely by being 'attached' to it then you are gonna have a bad time. Instead, think of binding of 'this' as usually only happening at call time, to the thing you are 'calling the function off of'.
In reference to case 1 (bare function call), this is the same behaviour which occurs when as defining an anonymous function inside a function which has 'this' set. Just don't use 'this' in this case, it doesn't make sense. Defining a _this or self variable in the parent function is the standard practice to deal with this case, or in ES6, Coffeescript etc. you have the => fat arrow to implicitly do that for you.
[0] http://llvm.org/devmtg/2013-11/slides/Zakai-Emscripten.pdf
Here's a jsfiddle for the specific lib you're talking about (Odometer): http://jsfiddle.net/p1h7rn3q/
As for the use of JSX specifically, it's handy because it allows expressing ordered associative data, for which in javascript the other choices are both kind of messy: either an array of objects (verbose) or an object (not guaranteed to be ordered).
John Oliver recently commented on this stuff (so called "Native Advertising") on Last Week Tonight: https://www.youtube.com/watch?v=E_F5GxCwizc