Let me see if I can answer a couple of these.
1)
Bitwise operators look pretty powerful, and based off of just some
quick reading I can see some interesting applications. It is not
something that I've used (up till this point) in a lot of my code but I
can see the uses.
For example:
http://jsfiddle.net/skhjpxg3/
The variable "name" is set as zero at the start. By using the name ^= 1
the system will flip the variable from 0 1 0 1 0 1 indefinitely. This
allows you to have a very effective toggle with very little overhead on
your code.
There are a ton more examples of applications and I think you could build some really interesting server side stuff.
This said as stated in this stackoverflow
http://stackoverflow.com/questions/654057/where-would-i-use-a-bitwise-operator-in-javascript
one user says that while it can be faster you sacrifice code
readability as it becomes much more difficult to understand exactly what
is going on in the application in a readable manner.
Testing this concept above against another method to toggle doesn't reveal a *huge* performance gain though:
http://jsperf.com/bitwisetest - i'd fine the second method in this example more readable.
2)
Singleton patterns are mainly effective when you need to have the
system only instantiate a class only one time to control some
application/global logic.
Here is an example :
http://jsfiddle.net/70eyj0v9/2/
-- The application variable holds an anonymous function which wraps our
UserName and UserAccess levels. Any other function can easily access
Application.getInstance().getUserName() without having to first
instantiate the class. **This is a very simple example, you would of
course add more logic into this application area**.
Understanding
the THIS keyword can be a pain in the ass because the scope can
sometimes jump back and forth depending on where the context is actually
at. You'd want to use the thisArg for the array so that the actual
array processing function can understand what this references. In the
above example the button click shows you what this returns with the
thisarg defined and not defined.
4) Sometimes you'd
want to return false so that the application can take some kind of
action if there was nothing returned from the function (sometimes).
There are also times where you want the default action to stop if
nothing should be returned, or that the default action should stop. For
example if you are writing an input box and only want the user to input
numbers you could test to make sure the input value is within a range
of keydown values and return false if it doesn't. This will roll up and
stop the input from happening.
5) The pattern that is described on page 60 is a little different than what you wrote. Here is an example I put together :
http://jsfiddle.net/e1wbncf3/1/ (using the code from the book).
The global scope is foo. Foo can be called with console.log(foo()) or console.log(foo) (which returns the actual function.)
But
we'd expect that the definition of local() with function bar() would
return "6" because it is returning the function that we expect to run
when local() is accessed. Instead it gives you back the function bar()
and doesn't actually return what we'd think it would.
As
shown in the example by clicking the button you can access "6" from
local bar, this would allow you to return back specific functions
depending on what you need and do it more or less anonymously. This is a
black hole of functionality and feature that allows your code to be
more flexible.
Your code is working because we're not attempting to access a function defined in a function (i think)
6)
The reason your code isn't working in this example is that you're
creating an infinite loop and the .pop() is never actually running.
http://jsfiddle.net/yjzzy9xs/In
this example all I did was move the .pop prior to the reexecution of
the function so that the application can properly get rid of the element
in the array.