Is it recommended/do I need to make use of the JavaScript new keyword? Is there any advantage to doing so?
If so, then how would I go about using it? I have got to grips with the majority of the language, just not the new constructor/keyword?
Is it recommended/do I need to make use of the JavaScript new keyword? Is there any advantage to doing so?
If so, then how would I go about using it? I have got to grips with the majority of the language, just not the new constructor/keyword?
Is it recommended/do I need to make use of the JavaScript new keyword? Is there any advantage to doing so?
If so, then how would I go about using it? I have got to grips with the majority of the language, just not the new constructor/keyword?
Using new
in JavaScript is for constructors and get the advantage of using prototypes instead of only functions Using new
in JavaScript is for constructors and get the advantage of using prototypes instead of only functions.
Check similar questions on Stack Overflow about the use of var
Check similar questions on Stack Overflow about the use of var
.
Ok, is long to answer, some puntual are asked before on stack overflow.
Using new
on javascript is for constructors and get the advantage of using prototypes instead of only functions [1] in this case I didn't see the necessity of use itUsing new
in JavaScript is for constructors and get the advantage of using prototypes instead of only functions. Your aproach is more near to declear a jquery plugin [2]
If you have more punctual doubts, I strongly recommend take a look on stack overflowStack Overflow.
Is a very oftenIt's good practice in the wholewith plugins and etc of jquery passingin jQuery to pass a buchbunch of things as options
object, forobjects. For me, isit's a code smell and I prefearprefer to analyze if isit's possible to split responsabilitiesresponsibilities or thing in terms of view/model
, but that is a personal choice.
Sometimes isit's hard to avoid the options
objectobjects because we have a lot of configs to set and fallback to defaults. In this case, you are wrapping in other function, and your extra params are only for you plugin convencion, so , i ́mI'm think isit's not wrong.
"it"It depends" is the best answer, you. Dou need that level of configuration?. Normally all jqueryjQuery plugins has a fallback options. I think could be a good idea move to options, if you are going to reconfigure, or need reconfigure. If not, that don ́t havedoesn't make sense.
According with the documentation of $.extend
the first param, is the target.
So So, isit's a good practice don ́tto not override the default parameters.
You You should have 2 objects options
/ settings
and merge in a interalinto internal options and use it.
About your code, global non-declared variables, are attached to window
.
Check similar questions on stackoverflow about the use of var
[4]Check similar questions on Stack Overflow about the use of var
.
Also i make some improvements in your code [5] and leave a few comentsAlso, I've made some improvements in your code and left a few comments.
In this example iI see you are triyingtrying to encapsulate ́myFunction ́ but i dontI don't see where are dfineddefined showLoader
when you call it.Should It should be a good practice to send inside of options instead of ask and execute.
Ok, is long to answer, some puntual are asked before on stack overflow.
Using new
on javascript is for constructors and get the advantage of using prototypes instead of only functions [1] in this case I didn't see the necessity of use it. Your aproach is more near to declear a jquery plugin [2].
If you have more punctual doubts, I strongly recommend take a look on stack overflow.
Is a very often practice in the whole plugins and etc of jquery passing a buch of things as options
object, for me, is a code smell and I prefear analyze if is possible split responsabilities or thing in terms of view/model
but that is a personal choice.
Sometimes is hard to avoid the options
object because we have a lot of configs to set and fallback to defaults. In this case, you are wrapping in other function, and your extra params are only for you plugin convencion, so , i ́m think is not wrong.
"it depends" is the best answer, you need that level of configuration?. Normally all jquery plugins has a fallback options. I think could be a good idea move to options, if you are going to reconfigure, or need reconfigure. If not that don ́t have sense.
According with the documentation of $.extend
the first param, is the target.
So, is a good practice don ́t override the default parameters.
You should have 2 objects options
/ settings
and merge in a interal options and use it.
About your code, global non-declared variables, are attached to window
.
Check similar questions on stackoverflow about the use of var
[4]
Also i make some improvements in your code [5] and leave a few coments.
In this example i see you are triying to encapsulate ́myFunction ́ but i dont see where are dfined showLoader
when you call it.Should be a good practice send inside of options instead of ask and execute.
If you have more punctual doubts, I strongly recommend take a look on Stack Overflow.
It's good practice with plugins in jQuery to pass a bunch of things as options
objects. For me, it's a code smell and I prefer to analyze if it's possible to split responsibilities or thing in terms of view/model
, but that is a personal choice.
Sometimes it's hard to avoid the options
objects because we have a lot of configs to set and fallback to defaults. In this case, you are wrapping in other function, and your extra params are only for you plugin convencion, so I'm think it's not wrong.
"It depends" is the best answer. Dou need that level of configuration? Normally all jQuery plugins has a fallback options. I think could be a good idea move to options, if you are going to reconfigure, or need reconfigure. If not, that doesn't make sense.
According with the documentation of $.extend
the first param is the target. So, it's a good practice to not override the default parameters. You should have 2 objects options
/ settings
and merge into internal options and use it.
About your code, global non-declared variables are attached to window
.
Check similar questions on Stack Overflow about the use of var
.
Also, I've made some improvements in your code and left a few comments.
In this example I see you are trying to encapsulate ́myFunction ́ but I don't see where are defined showLoader
when you call it. It should be a good practice to send inside of options instead of ask and execute.