Guest User

Untitled

a guest
Jan 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function Controller() {
  2. self = this;
  3.  
  4. self.createObject = createObject;
  5. function createObject() {
  6. new ObjectTest(self);
  7. }
  8.  
  9. self.createAlert = createAlert;
  10. function createAlert(text) {
  11. alert(text);
  12. }
  13. }
  14.  
  15. function ObjectTest(controller) {
  16. this.controller = controller;
  17. this.controller.createAlert("test");
  18. }
  19.  
  20. <body onload="new Controller.createObject()">
  21.  
  22. Uncaught TypeError: Object #<Controller> has no method 'createAlert'
  23.  
  24. <body onload="new Controller().createObject()">
  25.  
  26. function Controller() {
  27. self = this;
  28. self.createObject = function(){
  29. new ObjectTest(self);
  30. };
  31. self.createAlert = function(text) {
  32. alert(text);
  33. };
  34. }
  35.  
  36. (new Controller).createObject()
  37. // or
  38. new Controller().createObject()
  39.  
  40. new Controller.createObject()
  41. // which is like
  42. new (Controller.createObject)()
  43.  
  44. <body onload="new Controller.createObject()">
  45.  
  46. <body onload="new Controller().createObject()">
  47.  
  48. var Controller = {
  49. createObject: function () {
  50. return new ObjectTest(this);
  51. },
  52.  
  53. createAlert: function(text) {
  54. alert(text);
  55. }
  56. }
  57.  
  58. <body onload="Controller.createObject()">
Add Comment
Please, Sign In to add comment