Backbone dynamic elements

I recently discovered Backbone’s setElement function. What it allowed me to do was dynamically create a view’s container in Javascript and transfer/assign the view and its events to the new element.

Using jQuery within the view initialize event:

I manipulated the this.el attribute directly, without using an interim variable, it seemed to work ok, but if there are side-effects I discover later, it should be easy enough to change. setElement will automatically assign its argument to this.el so nothing further needs to be done.

REST Authentication

I did some research the other day to secure my REST API using The Slim framework.

I found a tidy little way to force HTTP authentication (basic, in this case) using this article as well as the PHP manual.

I get the client to provide the user name and password, then I can look up the (hashed) password in the database. It simply causes the call to authenticate each login with their corresponding password.

In combination with forcing the page through https (a .htaccess task) and this, I can protect API access pretty simply.

I used this in VB6 (and the great Chilkat components) to authenticate a PUT command. I can now more safely allow database inserts from over the Net. It was as simple as:

Next task is to find a more secure way to access the (read-only) API from JavaScript, without just embedding a password in the source code.  This looks like a great start.

New JavaScript book

Book CoverI got my new Javascript book delivered yesterday.  My first thought was that it was quite thin (it only has about 150 pages including the appendices and index)!  I took a look at the first section, and it’s quite thorough; the author himself states that it is quite information-dense, and that it will require a few readings to get it all.

I can’t say that I really like the railroad diagrams for describing the syntax of the language as much as I’d like more example code.  I suppose the diagrams are more inclusive, they just seem a little excessive for what information they provide.

Yes, this is an incredibly terse book.  Some rather hefty topics are given a few lines of discussion.  Not that this is terrible, but it makes for a slow read.  He establishes a few helper functions & methods to allow you to do certain tasks a lot easier, such as easier object creation and inheritance.  These functions are referred to later on in the book as if they were parts of the core language, so you really need to know both the book and the core language very well.

I can see how the techniques in this book would help a developer build quite complex applications in JavaScript. Many would reject that idea as foolish but considering what companies like Google have been able to provide using this language show that with some ingenuity and a whole lot of determination, you can create some remarkable things.