Joined January 2017
·

dibiler

I'd add before the for loop:
var container = document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0];

then replace that line inside the loop so you don't have to fetch the dom everytime.

Posted to Faster $(document).ready() over 1 year ago

It's good to note that while .live used to work with every element .on only works with element that existed before the .on function was defined.

So in the case of adding dynamic elements it's necessary to attach the event to an existing element (a parent of the dynamic ones, it may be event the document but it's better for performance the closest to the dynamic elements).

Then we need to filter our dynamic element with an additional parameter to .on like: $('.container').on('click','a',function(){...}); This example adds the event "click" to all tags "a" inside the ".container" element.

Or you can just extend it without using any external library:

var originalFunction = function() {
console.log("Original Function");
},
oldFunction = originalFunction,
originalFunction = function() {
oldFunction.apply(this, arguments);
console.log("Do something else after old function finished");
};

Posted to An updated most used jQuery function over 1 year ago

I would remove the last else and just return false at the end or return false inside the else instead of this.length>0 as it will only be reached if the condition is false, else it'll get inside the if and use its return instead.

Hi Alexander,
I was taking a look at your CommandManager code and I think I found a bug, when you click redo() you're actually pushing once more than you should the last thing that was done.
As you are already pushing the last function on the latest if, in the first if it only should be pushed once to readd the previously removed function with pop:
if (cmd2 === undefined){
cmd2 = CommandManager.executed.pop();
CommandManager.executed.push(cmd2); //needed to add last command removed in previous line
//Removed line: CommandManager.executed.push(cmd2);
}

if (cmd2 !== undefined){
  cmd2.execute();
  CommandManager.executed.push(cmd2); //this adds the executed command as usual
}

Also in this case may look too much but I would replace the content inside of the latest if with: this.execute(cmd2);

Achievements
1 Karma
0 Total ProTip Views