I cannot use custom function on NodeList returned by document.querySelectorAll

Forums » Dev.Opera » General Web Development Discussions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

26. April 2012, 11:02:08

jirisvoboda

Posts: 1

I cannot use custom function on NodeList returned by document.querySelectorAll

Both document.getElementsByTagName and document.querySelectorAll return NodeList object.

I extend NodeList.prototype with "myFunction":
NodeList.prototype.myFunction = function() { console.log("Hello, I am myFunction"); }

When I call:
document.getElementsByTagName("body").myFunction();
everything is right and "Hello..." is printed in console.

But when I call:
document.querySelectorAll("body").myFunction();
I get following error:
Unhandled Error: 'document.querySelectorAll("body").myFunction' is not a function

I this bug? Or am I doing something wrong?

Tested in console
on Opera 11.62 Build: 1347 and Opera 12.00 beta, Build 1387
Platform: Win32, System: Windows 7

30. April 2012, 21:24:16

spadija

Posts: 1636

I can confirm that. I don't know what the intended behavior is, but I would expect that it's a bug.

1. May 2012, 16:27:27

burnout426

Posts: 12424

This is CORE-26489. It's fixed internally. Not sure when the fix will be released.

Forums » Dev.Opera » General Web Development Discussions