Deciding what not to do is as important as deciding what to do.
Steve Jobs
Function bind polyfill
A polyfill function for ES5 Function.prototype.bind
:
|
|
Express - app.router
In ExpressJS 3.x, you may see a line code:
|
|
Briefly, app.router
is the component that knows what to do when you call app.get()
etc. See the Connect documentation for the router
middleware to understand what it does.
Why is order important?
If the router middleware was installed before the session middleware, your router handlers would run before the sesssion middleware so the session wouldn’t be setup until after your handler completed; if the route middleware was installed after the errorHandler middleware, errorHandler wouldn’t get a chance to deal with error from your route handler because it would have been run before the router handler got called.
Bacically, you need to install app.router
explicitly if you have other middleware that you need to ensure come after it in the stack.
References:
Split in javascript
In JavaScript, split
behaves a litte different than expected. For example, we have a string needed to be split into pieces:
|
|
Say, we need to split and format the above string into:
|
|
If we use split
without limitation:
|
|
Actually, we got:
|
|
So we add another argument:
|
|
Got Only [Steve Jobs]
. The result is not we except. The second argument just identify how many elments in the spilt pieces would return.
So we need to do the split
ourself:
|
|