Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Can.view Deferred getting resolved after controller has been destroyed

$
0
0
Such is the nature of async software that you need to make sure the app hasn't switched states by the time a task is complete.  Your last suggestion is just offloading the "this.element" check to jQuery... which is fine... and shorter code... and works.  But lets say I joined your team tomorrow and started editing your controller, I would say to myself "this.element is already a $-wrapped object - lets get rid of unnecessary function calls" - at which point the code would break again.  By writing an explicit check, while it takes about 2 seconds longer to code, helps tell other developers "hey, there are situations where this.element might be undefined".  You should also be able to do this shorthand:

  1. this.element && this.element.html(fragment); 

Viewing all articles
Browse latest Browse all 3491

Trending Articles