Posted on January 17th, 2017
Object.prototype which will return
Object.prototype. And herein lie the same dangers of open classes that Ruby has. If you find yourself with multiple libraries that increment
Object.prototype as their parent prototype, they use
Function.prototype (which is itself linked to
Object.prototype). As a consequence of being an object, functions can be attributed to variables, to arrays, passed as arguments to other functions or returned. This quirckiness in functions is the use of
this. For functions embeded in an object,
this refers to the object being a way to access the object's properties. Unfortunatelly, for functions nested in those functions,
this does not bind to that same object. The workaround is to use a variable with another name (conventionally
that) to trap the value of
return is the most known one and simply exits the current function returning whichever value was provided. If
return is never invoked in a function,
undefined is returned. Unless the function was invoked with
new (we call those functions constructors) in which case,
this (the object created) is returned.
throw is another one and serves as an exception flow like Java or Ruby have.
throw takes an object that is expected to have
message attributes and simply interrupts the execution of all functions in the stack until there is a
catch clause after a
Object.create) and then assign functions (or values) to the properties that the original object had.
Array.prototype) which has properties that are numbered from 0 to the length of that array. Arrays get (from their prototype) a
/s. There are capturing and non-capturing group as well as positive and negative lookahead. Regular expressions accept 3 modifiers (after the expression itself) that are
g for global (for multiple matches),
i for [case] insensitive,
m for multiline. If a regular expression is dynamic (and not hard-coded), one can use the
RegExp constructor to build the expression dynamically.