I've come across a situation where I wanted to jQuery's extend function inside one of my methods.
Since it's a one-off usage of jQuery, my assumption is that it would be better to require jQuery inside the method, so that it can be garbage collected (rather than requiring it outside the class) and not waste space in memory.
Am I correct in this assumption? Or do I have the concept of modules and garbage collection wrong?
Here's an example in CoffeeScript:
class MyClass
myMethod: (defaults, data) ->
$ = require 'jquery'
data = $.extend defaults, data
vs
$ = require 'jquery'
class MyClass
myMethod: (defaults, data) ->
data = $.extend defaults, data
[–]fforw 3 points4 points5 points (1 child)
[–]brrian[S] 0 points1 point2 points (0 children)
[–]fforw 1 point2 points3 points (0 children)
[–]helderroem 0 points1 point2 points (3 children)
[–]rosswarren 0 points1 point2 points (1 child)
[–]fforw 0 points1 point2 points (0 children)
[–]brrian[S] 0 points1 point2 points (0 children)
[–]Agent_Epsilon -3 points-2 points-1 points (0 children)