I am working on extJS webapp and was looking for a way to list all the names of my own objects. Google, I quickly found the link code for this blog . Now, when using this keys () method, I find strange behavior when listing property names of object objects. Code example:
keys = function(obj) { if (typeof obj != "object" && typeof obj != "function" || obj == null) { throw TypeError("Object.keys called on non-object"); } var keys = []; for (var p in obj) obj.hasOwnProperty(p) && keys.push(p); return keys; }; var test = {} test["nr1"] = {testid: 1, teststr: "one"}; test["nr2"] = {testid: 2, teststr: "two"}; test["nr3"] = {testid: 3, teststr: "three"}; for (var i in keys(test)) { console.log(i); }
When you run this code, the console displays:
0 1 2 remove()
Thus, the "remove ()" function is also displayed at the top of the expected property names 3. This is clearly related to ExtJS because the enumeration works as expected on an empty download page other than ExtJS.
Can someone explain to me exactly what ExtJS is doing here? Is there a better way to list property names of an object-object?
Thanks wwwald
source share