Javascript Controller Loading/unloading

r3wt

Most of these questions don't have very comprehensive answers.

say in my application, i've decided to call whatever controller is currently loaded something like $app.ctrl

now when i set $app.ctrl to null, what about any events that controller created?

for instance, my app might load a controller like this:

loadController : function(controller){
    $app.ctrl = null;
    var s = document.createElement('script');
    s.setAttribute('src', $app.ctrl_path+controller);
    s.className = 'ctrl';
    s.onload= function(){
        $app.ctrl = $ctrl;
        $app.ctrl.initialize();
    };
    document.body.appendChild( s );
},

How will events and instantiated plugins be cleaned up? what if my controller does lots of nasty stuff with jQuery plugins and adding event listeners and sech? Will GC really destroy these events, or will they secretly remain lurking, waiting to cause havoc: (suprise, they do)

var $ctrl = {

    initialize : function(){
        $(window).on('resize',function(){
            alert('you resized');
        });
    }

};

So what's the solution here? should my $app object define setters and getters for events, and a clean method for controllers? then the controller defiles a list targets and their events? so confused.

I think its pathetic that in 2015 javascript is this worthless in every modern browser.

krl

The solution is to have and call de-initialize function with .off():

reference:

https://api.jquery.com/off/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript in Controller Codeigniter

From Dev

JavaScript not firing method in the controller

From Dev

Pass Data from Controller to JavaScript

From Dev

using controller variable in javascript in phoenix

From Dev

JavaScript not Sending Parameter to Controller MVC

From Dev

Passing javascript variables to rails controller

From Dev

Accessing angular controller from javascript

From Dev

AngularJS pass Javascript object to controller

From Dev

Read in javascript a spring controller model

From Dev

rails controller action AND javascript onclick

From Dev

Passing javascript variables to rails controller

From Dev

Call controller method from javascript

From Dev

Pass Data from Controller to JavaScript

From Dev

using controller variable in javascript in phoenix

From Dev

How to access controller variable in javascript

From Dev

Passing values to controller using javascript

From Dev

javascript exception in while controller in jmeter

From Dev

Transmit javascript object into controller action as dictionary

From Dev

Static javascript variable to be used as counter in Angularjs controller

From Dev

Send JSON object from rails controller to Javascript

From Dev

Sending data from javascript to Controller Yii

From Dev

pass javascript response variable to spring controller function

From Dev

Get the MVC controller name in Javascript function

From Dev

JavaScript | Angular | Controller As Syntax: Cannot Use `this`

From Dev

Javascript object received as null in mvc controller

From Dev

Passing list to javascript to pass back to controller

From Dev

How to call javascript function in the index of a controller in codeigniter?

From Dev

rails 4 controller redirect not loading javascript

From Dev

how to access Javascript multidimensional array in MVC controller

Related Related

  1. 1

    Javascript in Controller Codeigniter

  2. 2

    JavaScript not firing method in the controller

  3. 3

    Pass Data from Controller to JavaScript

  4. 4

    using controller variable in javascript in phoenix

  5. 5

    JavaScript not Sending Parameter to Controller MVC

  6. 6

    Passing javascript variables to rails controller

  7. 7

    Accessing angular controller from javascript

  8. 8

    AngularJS pass Javascript object to controller

  9. 9

    Read in javascript a spring controller model

  10. 10

    rails controller action AND javascript onclick

  11. 11

    Passing javascript variables to rails controller

  12. 12

    Call controller method from javascript

  13. 13

    Pass Data from Controller to JavaScript

  14. 14

    using controller variable in javascript in phoenix

  15. 15

    How to access controller variable in javascript

  16. 16

    Passing values to controller using javascript

  17. 17

    javascript exception in while controller in jmeter

  18. 18

    Transmit javascript object into controller action as dictionary

  19. 19

    Static javascript variable to be used as counter in Angularjs controller

  20. 20

    Send JSON object from rails controller to Javascript

  21. 21

    Sending data from javascript to Controller Yii

  22. 22

    pass javascript response variable to spring controller function

  23. 23

    Get the MVC controller name in Javascript function

  24. 24

    JavaScript | Angular | Controller As Syntax: Cannot Use `this`

  25. 25

    Javascript object received as null in mvc controller

  26. 26

    Passing list to javascript to pass back to controller

  27. 27

    How to call javascript function in the index of a controller in codeigniter?

  28. 28

    rails 4 controller redirect not loading javascript

  29. 29

    how to access Javascript multidimensional array in MVC controller

HotTag

Archive