Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:04:38+00:00 2026-06-01T14:04:38+00:00

For executing array methods on NodeList objects(Array like) we need to make indirect call

  • 0

For executing array methods on NodeList objects(Array like) we need to make indirect call on Array.prototype every time.

Can we do something so that node_list.slice(0,1) is possible?

As NodeList inherits methods from Object.prototype, i implemented like below and works
perfectly node_list.slice(0,1)

Object.prototype.slice = function(a,b){ return Array.prototype.slice.call(this,a,b);}

Is there any disadvantage on implementing slice on Object.prototype?

Legacy way to call on Array.prototype:

node_list
[<li>​ test_list1 ​</li>​, <li>​ test_list2 ​</li>​]

Object.prototype.toString.call(node_list)
"[object NodeList]"

var content = Array.prototype.slice.call(node_list,0,1)

content
[<li>​ test_list1 ​</li>​]

Object.prototype.toString.call(content)
"[object Array]"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:04:39+00:00Added an answer on June 1, 2026 at 2:04 pm

    It’s a bad idea to extend the Object’s prototype for this reason.
    Even if you want to extend a built-in prototype, reduce the extension to the necessary parts:

    HTMLCollection
    NodeList
    

    Prototype methods which don’t show up in a for(.. in ..) loop can be defined as follows:

    var slicer = { value: Array.prototype.slice };
    Object.defineProperty(HTMLCollection.prototype, 'slice', slicer);
    Object.defineProperty(NodeList.prototype, 'slice', slicer);
    

    See also:

    • Object.defineProperty

    Shortest way (without extending prototypes)

    // Equivalent to the question's code
    [].slice.apply(node_list,0,1)
    // A method to turn a node_list/HTMLCollection in an array (for later use?)
    [].slice.call(node_list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting NSMutableArray values on class2. Array is filled and retained while executing
When executing :make from vim, after make is complete it automatically jumps to a
I'm reading an array of JSON objects from an API, and hope to use
I need to compare a 1-dimensional array, in that I need to compare each
I need to call the getItem() method inside the runnable. But the thing is
What could be the problem with reversing the array of DOM objects as in
I would like to filter return values of methods which have a @Filter annotation
I would like to call the following java method from scala: protected final FilterKeyBindingBuilder
Is there a jQuery equivalent to prototype's defer? I'm looking for something that will
Executing this code: mainLyr = [[CALayer layer] retain]; [mainLyr setFrame:CGRectMake(0.0,0.0,23.0,23.0)]; in debugger, I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.