Character-Limit for Textareas

Character-Limit for Textareas

I'm trying to add a Character-limit on all Textareas using this code:

  1. var limitNum = 40;
  2. $('.textarea__field').keyup(function(limitField, limitNum) {
  3.   if (limitField.value.length > limitNum) {
  4.     limitField.value = limitField.value.substring(0, limitNum);
  5.   }
  6. });

Why it's not working?

Thanks