I am trying to replace any spaces in my input on change. I am using ng-change
directive to accomplish that. I would normally write my code like this because I want the removeInvalidCharacters
function to be reusable hence the model being passed as parameter.
<input model="vm.model.code" ng-change="vm.removeInvalidCharacters(vm.model.code)" />
and JS
vm.removeInvalidCharacters = function(text) {
text = text.replace(/ /g, '');
};
I have read on the airbnb javascript style guide that this is a bad practice and we should return the value. To be exact we shouldn't "mutate a parameter" (Never reassign parameters). What is the right way to do it and still keep the reusable function?