How does a jQuery instance appear as an array when called in console.log?

后端 未结 5 1903
一个人的身影
一个人的身影 2021-01-03 15:58

When entered into a JavaScript console, a jQuery object appears as an array. However, it\'s still an instance of the jQuery object.

var j = jQuery();
=> [         


        
5条回答
  •  甜味超标
    2021-01-03 16:05

    I believe they have something like that:

    // Adding items to an object like an Array:
    var myObject = {splice : Array.prototype.splice};
    
    Array.prototype.push.call(myObject, 1, 10, "foo");
    
    // Getting items from an object like an Array:
    
    alert(Array.prototype.slice.call(myObject, 0));
    
    console.log(myObject);
    
    alert(myObject);
    

提交回复
热议问题