I need new method for the object. And I'm trying to create it:
Object.prototype.getByPath = function (path, other) {
for (var i=0, obj=this, path = path.split('.'), len=path.length; i<len; i++) {
obj = obj[path[i]];
}
return (typeof obj === "undefined" || obj == "") ? other : obj;
}
But this code return an error (Conflict with another js file!):
Uncaught TypeError: Object function (path, other) {
Another js file start with this line:
(function(){function d(a,b){
try {
for (var c in b)
Object.defineProperty(a.prototype, c, {value:b[c],enumerable:!1})
} catch(d) {
a.prototype = b
}
}());
How can I solve this error?
Object
prototype?? This will add thegetByPath
method to all objects – jasonscript Nov 25 '13 at 6:15());
. – RobG Nov 25 '13 at 6:27