var returned = values.make(function (value, index) {
return items[index].value = value;
});
I have the above snippet.
Values is an array of values to be assigned to different elements.
Make is essentially the equivalent of Array.prototype.map.
Array.prototype.make = function (loop, playground) {
var loop = loop || function (value) { return value },
playground = playground || this;
if (loop.Type !== "Function") throw "Loop [0] is not a function.";
var returned = [];
for (var i = 0; i < this.length; i++)
returned[i] = loop.apply(playground, [this[i], i, this]);
return returned;
};
Also, I have Function.prototype.Type = "Function";
in the same file, so it's not .Type
throwing an error. .Type
works perfectly.
Along with Function, these also have .Type
's.
Object.prototype.Type = "Object";
Array.prototype.Type = "Array";
RegExp.prototype.Type = "RegExp";
String.prototype.Type = "String";
Number.prototype.Type = "Number";
Boolean.prototype.Type = "Boolean";
XMLHttpRequest.prototype.Type = "XMLHttpRequest";
Date.prototype.Type = "Date";
Items is the array of different elements.
[<input type="text" />, <input type="text" />, <input type="text" />]
I keep getting this error.
Uncaught Error: NOT_SUPPORTED_ERR: DOM Exception 9 on line 3
I get that error and it doesn't make any sense, because there isn't any code on that line.
I'm at a total loss.
Does anyone notice anything wrong with that code?
Update: I don't know what happened, but I fixed it.
Since no one gave the correct answer, I'll just give it to the only guy who tried.
*clap clap clap*
var returned = values.make(function (value, index) {
return items[index].value = value;
});
I have the above snippet.
Values is an array of values to be assigned to different elements.
Make is essentially the equivalent of Array.prototype.map.
Array.prototype.make = function (loop, playground) {
var loop = loop || function (value) { return value },
playground = playground || this;
if (loop.Type !== "Function") throw "Loop [0] is not a function.";
var returned = [];
for (var i = 0; i < this.length; i++)
returned[i] = loop.apply(playground, [this[i], i, this]);
return returned;
};
Also, I have Function.prototype.Type = "Function";
in the same file, so it's not .Type
throwing an error. .Type
works perfectly.
Along with Function, these also have .Type
's.
Object.prototype.Type = "Object";
Array.prototype.Type = "Array";
RegExp.prototype.Type = "RegExp";
String.prototype.Type = "String";
Number.prototype.Type = "Number";
Boolean.prototype.Type = "Boolean";
XMLHttpRequest.prototype.Type = "XMLHttpRequest";
Date.prototype.Type = "Date";
Items is the array of different elements.
[<input type="text" />, <input type="text" />, <input type="text" />]
I keep getting this error.
Uncaught Error: NOT_SUPPORTED_ERR: DOM Exception 9 on line 3
I get that error and it doesn't make any sense, because there isn't any code on that line.
I'm at a total loss.
Does anyone notice anything wrong with that code?
Update: I don't know what happened, but I fixed it.
Since no one gave the correct answer, I'll just give it to the only guy who tried.
*clap clap clap*
Share Improve this question edited Apr 13, 2011 at 20:30 McKayla asked Apr 13, 2011 at 18:15 McKaylaMcKayla 6,9596 gold badges39 silver badges49 bronze badges 20- This question deals with the same error message. You might find some useful information there. – jrn.ak Commented Apr 13, 2011 at 18:18
-
Can you provide a simple example that produces the same error? Also, the source for
make()
would help. – Vivin Paliath Commented Apr 13, 2011 at 18:19 - Can you post rest of the code? Specially make – Chandu Commented Apr 13, 2011 at 18:19
- @Tesserex It says in the question. Right about the error message. It's a bunch of input elements on an page. – McKayla Commented Apr 13, 2011 at 18:19
-
The error is probably ing from
make()
, can you include that code and also theitems
array? – mVChr Commented Apr 13, 2011 at 18:19
2 Answers
Reset to default 5Can you post a small example that reproduces this error?
Other than that, there are a few errors in your Javascript:
I added a semicolon here:
var loop = loop || function (value) { return value; },
playground = playground || this;
Although semicolons are not necessary, I like to use them because otherwise you can be bitten by subtle errors.
And, you need to use typeof
not .Type
:
if (typeof loop !== "function") throw "Loop [0] is not a function.";
Also, if items
is just an array of strings as you have, then items[index].value
doesn't make sense, since strings don't have a value
property. This part looks particularly suspicious to me. Although I didn't get the same error you did when I left that bit in, I think it would merit closer examination.
You mentioned that you're using a 3rd-party library so the part about typeof
doesn't matter. You also mentioned that you were using actual input
elements in your array so the second part doesn't matter either.
I tried out your code again, this time creating input
elements with document.createElement
:
Array.prototype.make = function (loop, playground) {
var loop = loop || function (value) { return value; },
playground = playground || this;
if (typeof loop !== "function") throw "Loop [0] is not a function.";
var returned = [];
for (var i = 0; i < this.length; i++)
returned[i] = loop.apply(playground, [this[i], i, this]);
return returned;
};
var items = [];
items.push(document.createElement("INPUT"));
items.push(document.createElement("INPUT"));
items.push(document.createElement("INPUT"));
var values = [4, 5, 6];
var returned = values.make(function (value, index) {
return items[index].value = value;
});
console.log(items[0].value, items[1].value, items[2].value);
//firebug shows: 4 5 6
So it appears that your code is working by itself. Can you try this code out by itself on a fresh page? That way you can verify if it is something on the original page that is interacting with your code and causing this error.
I was having the same issue in a different scenario, but using the latest version of Prototype (1.7 instead of 1.5) fixed it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745334278a4623030.html
评论列表(0条)