Someone helped me with a great object prototype for JavaScript but it breaks in jQuery. In jQuery it gives an error:
jquery.min.js:2 Uncaught TypeError: V[g].exec is not a function
I found that the Object.defineProperty block (below) stops the jQuery error. But then it doesn't work. When I call to multiparter() it just returns "undefined". Can anyone help with a solution?
Object.prototype.multiparter = function(route) {
var newObj = this;
route.forEach(function(key) {
newObj = newObj[key]
});
return newObj;
};
Object.defineProperty(Object.prototype, 'multiparter',{
value : function() {},
enumerable : false
});
var mekBldr = {
mecha: {
heads: {
head01: {
cost: 0,
classification: ''
}
},
rightLimbs: {
legs: {
rightleg01: {
cost: 0,
classification: ''
}
}
},
leftLimbs: {
legs: {
leftleg01: {
cost: 0,
classification: ''
}
}
}
}
};
var part = 'heads';
var stuck2 = [part];
var part1 = 'leftLimbs';
var part2 = 'legs';
var stuck = [part1, part2];
mekBldr.mecha.multiparter(stuck2).head01.cost = 2;
//goal: mekBldr.mecha.leftLimbs.legs.leftleg01.cost = 5;
mekBldr.mecha.multiparter(stuck).leftleg01.cost = 5;