Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. Object.prototype.hasProperty = function(properties) {
  2. var finalProperty = this;
  3. var property;
  4. var child;
  5.  
  6. if (properties === undefined) {
  7. return true;
  8. } else if (properties.constructor !== Array) {
  9. properties = [properties];
  10. } else if (properties.length === 0) {
  11. return true;
  12. }
  13.  
  14. property = properties.shift();
  15. child = this[property];
  16.  
  17. if (child === undefined) {
  18. return false;
  19. } else {
  20. return child.hasProperty(properties);
  21. }
  22. }
  23.  
  24. var a = {b: {c: {}}};
  25.  
  26. if (a.hasProperty(['b', 'c'])) {
  27. console.log("definido!");
  28. } else {
  29. console.log("indefinido!");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement