Joined October 2012
·
mlb

Matthias Le Brun

Paris, France
·
·
·

Posted to Some random JS tips over 1 year ago

Nope, it's supposed to represent a regular object.

Be careful with this, thought :

~~9999999999.3
// 1410065407

Just for the record, I developed a library-agnostic script to do it (if you don't want be forced to use jQuery, which may be in your wish if you don't want to use something massive) : http://cl.ly/MEqo

@malladye Sorry ?

@alanaktion This function enables CSS styling on mentioned elements (to make them behave as they should you need to use header,footer,section,aside,nav,article,figure,hgroup,figcaption{display:block} though).

Posted to Javascript Quiz 1 over 1 year ago

JavaScript is a top-to-bottom, left-to-right parsed language, so it should act like this :

arr = [1, 5, 3]
i = 1
arr[1] /* i == 2 */ = arr[2] /* i == 3 (the "++" isn't actually relevant here) */
arr

Just forked your script :)
http://jsfiddle.net/yM5n5/1/

Posted to Stylus over 1 year ago

Stylus is my favorite one. The one that reduces the most the time I spend writing CSS.

Posted to jQuery caching over 1 year ago

Good if your DOM don't change between two calls.

Posted to .live() is dead <- carry .on() over 1 year ago

This is actually

jQuery, on clicking on the document, checks if the target is the element with the trackThis id, and if so, performs this function.

That's why on is good to attach handler to multiple elements, but if you check an id, you'd better attach the handler directly to the unique element.

Posted to Array comparison in plain JavaScript over 1 year ago

With a few performance improvements :

Array.prototype.isEqualTo = function (compareTo) {
  var self = this // cache array
    , length = self.length // cache length
  if(length != compareTo.length) return false // compare numbers, strict equalty isn't necessary
  for(;length--;) if(self[length] !== compareTo[length]) return false // decrement is faster with for loops
  return true
}

@newsociallife Thank you captain obvious!

@thomaspuppe By the way I usually recommend to jQuery users to create a helper like :

function $$(id){return $(document.getElementById(id))}

Even if '#id' selectors are optimized, they remain really slow compared to the helper,

Posted to Faster Ajax For WordPress over 1 year ago

Also, a GET request -when safe- is much quicker to initialize and to execute in JavaScript than a POST one.

@thomaspuppe Sizzle selectors are handled right to left. Your whole comment suffers from this wrong belief.

Posted to Just make a bookmarklet over 1 year ago

For a bookmaklet I'd rather do something smaller than that, even if that doesn't throw an alert :

javascript:(function(d,u,s){s=d.createElement("script"),s.src=u+"?"+(+new Date()),d.body.appendChild(s)})(document,"//domain.com/your/url")

As Function#bind isn't that fast, I'd rather use a simple Function#call here.

UselessDelay.prototype.start = function(){
  var self = this
  window.setTimeout(function(){
    self.show.call(self)
  }, 1000)
}
Posted to parseInt() can be dangerous over 1 year ago
"023" >> 0

is actually the faster way to perform a integer parsing.

HI!

I think that, for performance reasons I'd first put what has been passed in local variables :

function Person (options) {
  var self = this
    , firstName = options.firstName || "John"
    , lastName = options.lastName || "Smith"
    , age = options.age || 12
    , gendre = options.gendre || "male"
    , eyeColor = options.eyeColor || "brown"

  // some code here

  $.extend(self, {
    firstName : firstName,
    lastName : lastName, 
    age : age,
    gendre : gendre,
    eyeColor : eyeColor
  })
} 

The basic function is here a little more complex, but minifying local variable names is possible whereas object properties can't be changed (it's interesting if you perform tasks with the passed arguments). Also, as I said : http://mlb.tl/L7eQ

Cheers

@rstacruz I am sorry, but you're wrong, Element#innerHTML works really well with this trick. (as you can see here : http://mlb.tl/L7GF)

@benjamine Well :

The initial problem is : Some new HTML5 tags just don't work in old browsers. Why ? Because it doesn't recognizes them. But if the browser doesn't support an element, creating it using JavaScript simply makes it existence possible.

What we need here is to activate :
"header footer section aside nav article figure figcaption hgroup time"

The String#replace trick is a way of avoiding a for loop. The /\w+/g RegExp targets words, and the second argument, the function, is executed for each word (that's the role or the "g" in the RegExp). Then we just have to create elements using document.createElement.

Putting this script at the very beginning of the page makes the whole page ready to recognize these tagNames.

Posted to $ git pull my finger over 1 year ago

gooby pls

Posted to $.Crash Ie 6 over 1 year ago

Alternatively : http://mlb.tl/KxAw

Achievements
447 Karma
16,399 Total ProTip Views