• copy array in javascript

    var x = [1, 2];
    var y = x.slice(0);
    y[0] = 100; //y --> [100, 2]
    alert(x[0]); //1
    ​

    The new copy evolve independently of the old copy.

  • Easy Setter Functions in jquery

    One of the new feature in jQuery 1.4 is setter function. For a while now, you’ve been able to pass a function into .attr() and the return value of that function is set into the appropriate attribute. This functionalilty has now been extended into all setter methods: .css(), .attr(), .val(), .html(), .text(), .append(), .prepend(), .before(), .after(), .replaceWith(), .wrap(), .wrapInner(), .offset(), .addClass(), .removeClass(), and .toggleClass(). Addtionally, for the following options, the current value of the item is passed into the function as the second argument: .css(), .attr(), .val(), .html(), .text(), .append(), .prepend(), .offset(), .addClass(), .removeClass(), and .toggleClass().

    $('a[target]').attr("title", function(i, currentValue){
      return currentValue+ " (Opens in External Window)";
    });
    
    
  • how to test whether a object has member

    Object.prototype.hasMember = function (memberName)
      {
        return memberName in this;
    
    
  • how jQuery use sizzle selector

    The call stack is as follow <pre data-sub="prettyprint:_">return new jQuery.fn.init( selector, context ); return (context || rootjQuery).find( selector ); jQuery.find( selector, this[i], ret ); return makeArray(context.querySelectorAll(query), extra );

  • the internal of $.end() method

    jQuery methods that alter the original jQuery wrapper set selected are considered to be destructive.The reason being that they do not maintain the original state of the wrapper set. Not to worry;nothing is really destroyed or removed. Rather, the former wrapper set is attached to a new set.

    pushStack: function( elems, name, selector ) {
     // Build a new jQuery matched element set
     var ret = jQuery();