Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Controller() {
- self = this;
- self.createObject = createObject;
- function createObject() {
- new ObjectTest(self);
- }
- self.createAlert = createAlert;
- function createAlert(text) {
- alert(text);
- }
- }
- function ObjectTest(controller) {
- this.controller = controller;
- this.controller.createAlert("test");
- }
- <body onload="new Controller.createObject()">
- Uncaught TypeError: Object #<Controller> has no method 'createAlert'
- <body onload="new Controller().createObject()">
- function Controller() {
- self = this;
- self.createObject = function(){
- new ObjectTest(self);
- };
- self.createAlert = function(text) {
- alert(text);
- };
- }
- (new Controller).createObject()
- // or
- new Controller().createObject()
- new Controller.createObject()
- // which is like
- new (Controller.createObject)()
- <body onload="new Controller.createObject()">
- <body onload="new Controller().createObject()">
- var Controller = {
- createObject: function () {
- return new ObjectTest(this);
- },
- createAlert: function(text) {
- alert(text);
- }
- }
- <body onload="Controller.createObject()">
Add Comment
Please, Sign In to add comment