Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:479517
1 2 3 4 5 6 7 8 9 10 11 12 13
// How it probably should be done:
var options = Array.prototype.slice.call(arguments),
length = options.length,
thisObj = options.shift(),
script = document.createElement('script');
 
// How I sometimes do it...
var ops = Array.prototype.slice.call(arguments),
len = ops.length,
hoc = ops.shift(),
scr = document.createElement('script');
 
// Btw, 'hoc' is 'this' in Latin...

I usually just move the ='s over:
var options = Array.prototype.slice.call(arguments, 0),
length = options.length,
thisObj = options.shift(),
script = document.createElement('script');

But it just depends on the length of the var list and the look.

###15.4.4.10 Array.prototype.slice (start, end)

The slice method takes two arguments, start and end, and returns an array containing the elements of the array from element start up to, but not including, element end (or through the end of the array if end is undefined). If start is negative, it is treated as length+start where length is the length of the array. If end is negative, it is treated as length+end where length is the length of the array. The following steps are taken:

...

5 . Let relativeStart be ToInteger(start).

ToInteger(start) will produce 0 if the start is undefined.

However, I have noticed some implementations will error when passing an explicit undefined end argument [].slice(0, undef).
So I may be overly cautious but I like to at least pass a start argument of 0.

Owner

@jdalton,

I've never encountered an issue with slice() (no args), but I guess it wouldn't hurt to add a 0 ... just in case!

I like the idea of moving the =... although I might also tab the identifiers so that they line up (not sure if that was a mistake):

var options = Array.prototype.slice.call(arguments, 0),
    length  = options.length,
    thisObj = options.shift(),
    script  = document.createElement('script');

Cool. On tabbing the identifiers, I usually do a one space indent for multi-line var lists. (my coding style has been influenced by bits of PrototypeJS, Andrew Dupont, and Diego Perini)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.