Overview: Today we will take our feedback jQuery and turn it into a more re-usable plugin
$$ references (not the good kind)
$.extend()has the answer for us.
$('#showFeedbackForm')), lets allow those the selectors to be passed in, so that our code only ever references the property that they were assigned to. Here is an example of how we can do that, and then we can apply the same principle to our plugin:
See the Pen inject modal HTML into body by Mike P (@mikedemo) on CodePen.
$in our code, we are using jQuery to do something. Many times, this is not necessary as we have seen, and the plain old JS way is roughly as much code. To write the most efficient client side code we can, we need to limit (or ultimatly not use) jQuery references. A browser will execute plain JS significantly faster than it will execute jQuery, so we want to take advantage of that when we can. The goal is not to make your life hard, we will certainly use jQuery, but to save on performance when we can. Go for the low hanging fruit to start, such as instead of
$(this).val()just do
this.value