Bob Gray
Member since Jul 19, 2011
- Profile: /members/8651-bob-gray.htm
- Comments: 16
Recent Blog Comments By Bob Gray
-
Implementing Java's Collections.Shuffle() In JavaScript
Posted on Apr 4, 2014 at 12:01 PM
@Federico When valuing one approach over another I think it is important state the criteria. At times I've gone too far down the road of optimizing to later regret lack of clarity and simplicity of the code. I suspect for most it would be a rare occasion that required the need to shuffle 1000000 it... read more »
-
The Principles Of Object-Oriented JavaScript By Nicholas Zakas
Posted on Apr 1, 2014 at 9:50 AM
I've recently read Maintainable JavaScript and High Performance JavaScript both by Nicholas Zakas and I thought they were worth reading. I tend to agree with you on constructors. One argument against constructors is their overloaded nature. All constructor are functions and all functions co... read more »
-
Implementing Java's Collections.Shuffle() In JavaScript
Posted on Apr 1, 2014 at 9:23 AM
Another option for shuffling a JavaScript array is passing a shuffle function into the native .sort() method. numbers.sort(shuffle); function shuffle () { return Math.round(Math.random()) - 0.5; } Here is a post to a discussion on Fisher-Yates vs the above bubble sort approach. h... read more »
-
ColdFusion 10 - Creating A ColdFusion WebSocket AMD Module For Use With RequireJS
Posted on Mar 14, 2012 at 10:02 AM
Awesome post Ben! I'm very excited about CF 10 native websocket support. I completely agree with your application event approach and the idea of client code being loaded as an AMD vs <cfwebsocket/>. Nice work.... read more »
-
ColdFusion Supports HTTP Verbs PUT And DELETE (As Well As GET And POST)
Posted on Feb 6, 2012 at 8:57 AM
@Ben According to RFC 2616 ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html ) HEAD should be identical to GET without a body. OPTIONS is another interesting method intended to be used to communicate the service options available.... read more »
-
Creating A Keyboard-Shortcuts Module In A Modular JavaScript Application
Posted on Jan 24, 2012 at 11:13 AM
I like the idea of KeyboardShortcuts being it's own module. The business of ignoring events or unbinding when the target is an input is definitely a candidate for abstraction and reuse. I think the KeyboardShortcuts module triggering a "nextColor" event seems outside of its concern. If Co... read more »
-
Experimenting With A JavaScript Gateway To A Remote ColdFusion Persistence API
Posted on Dec 31, 2011 at 9:29 PM
I recently noticed that when ColdFusion errors it natively returns a server-error: true header, so I started looking for that on the client in ajax responses and setting it on the server when I cfcatch an error. It has made debugging remote cfc calls a bit easier.... read more »
-
Extending JavaScript Arrays While Keeping Native Bracket-Notation Functionality
Posted on Dec 5, 2011 at 11:54 AM
@Ben, I tried the Catalog example in FF from my previous post and it seemed to work fine at first. var foo = new Catalog(); foo.push( "a" ); // ["a"] foo[0] = 1; // [1] foo.length === 1; // true But then I dug a little deeper to try and get at the problem you were se... read more »
-
Extending JavaScript Arrays While Keeping Native Bracket-Notation Functionality
Posted on Dec 1, 2011 at 1:21 PM
Array.apply looks like a nice way to clone an array (its children still only being copied by reference). myArr.concat() and myArry.slice() works as well. I've had luck sub-classing Array by simply assigning myConstructor.prototype = []; and this.length inside myConstructor. IE7 doesn't set... read more »
-
Changing The Execution Context Of JavaScript Functions Using Call() And Apply()
Posted on Oct 7, 2011 at 5:05 PM
@mahdi, Neither snippet is right or wrong. Your example will bind the context as well as arguments. Mine will only bind the context. If you're not passing additional arguments beyond the context ( which I often don't ), there is no need to slice the arguments. If you wish to bind arguments as wel... read more »
-
Changing The Execution Context Of JavaScript Functions Using Call() And Apply()
Posted on Oct 5, 2011 at 10:56 AM
@nelle The script you posted is capable of currying a function as well. It can accept additional arguments and apply them as well as the context. If you want a script that only binds the this and doesn't have the additional overhead, you could use: function fnBind ( context, fn ) { ret... read more »
-
Changing The Execution Context Of JavaScript Functions Using Call() And Apply()
Posted on Oct 5, 2011 at 10:12 AM
@WebManWalking I've never thought about .call.call before. I tried it after reading your comment. I believe however that it is actually a circular reference and not that it doesn't exist until you call it. All objects in JS are passed by reference and functions are objects. Consider: var... read more »
-
jQuery Plugin: triggerHandlers() - To Trigger Handlers On All Selected Elements
Posted on Aug 5, 2011 at 9:20 AM
@Dan, I was intrigued by your use of .eq for getting the jQuery objects inside your each loop. It got me thinking that it would be nice to roll that into an "eachjQ" method. Seems Ben Alman ( and probably others ) beat me to it. .each2() http://benalman.com/projects/jquery-mi... read more »
-
Trying Out LAB.js For Asynchronous JavaScript (Script) Loading
Posted on Jul 22, 2011 at 12:08 PM
Your exactly right. Really it is JSONP. That is if you don't restrict your definition of JSONP to callback( /*entire response*/ ); I tend to think of JSONP and script tag insertion almost as one in the same. Consider the following hypothetical insert: var hello = doSomething(); doSomet... read more »
-
Trying Out LAB.js For Asynchronous JavaScript (Script) Loading
Posted on Jul 21, 2011 at 9:23 AM
My last post may have been a bit confusing. I wasn't intending the API url to be a link but an example of the script src. That source can be used with a dynamic script tag insert - something like: // needs to be globally accessible function init () { new google.maps.Map({ ... } // call... read more »
-
Trying Out LAB.js For Asynchronous JavaScript (Script) Loading
Posted on Jul 19, 2011 at 11:34 AM
Google maps API actually has a callback parameter that can be used for asynchronously loading. http://maps.googleapis.com/maps/api/js?sensor=false&callback=yourGlobalCallbackFn I haven't used LAB.js so I don't know how to leverage the callback param to make it work but I've written a custom ... read more »