Guest User

Untitled

a guest
Aug 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. How to get data from a JavaScript Object Literal
  2. this.objName = {
  3. fn : function () {console.log("????");}
  4. }
  5.  
  6. this.objName.fn() // objName
  7.  
  8. this.ns = {};
  9. this.ns.objName = {
  10. fn : function () {
  11. for (var k in ns)
  12. if (this === ns[k]) {
  13. alert(k);
  14. return;
  15. }
  16. }
  17. }
  18.  
  19. this.ns.objName.fn(); // objName
  20.  
  21. var Obj = new function() {
  22. this.objName = {
  23. id: 42,
  24. makeLink: function () {
  25. var self = this;
  26. document.getElementById("someelement").onclick = function(e) {
  27. alert(self.id); // 42
  28. };
  29. }
  30. }
  31. }
  32.  
  33. this.objName.fn()
Add Comment
Please, Sign In to add comment