Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.prototype.hasProperty = function(properties) {
- var finalProperty = this;
- if (properties.constructor !== Array) {
- properties = [properties];
- }
- try {
- properties.forEach(function checkProperty(property) {
- finalProperty = finalProperty[property];
- });
- } catch (e) {
- return false;
- }
- return finalProperty !== undefined;
- }
- var a = {b: {c: {}}};
- if (a.hasProperty(['b', 'c'])) {
- console.log("definido!");
- } else {
- console.log("indefinido!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement