I have the following script to delete a the digits at the end of an string and memorize the
initValues: (input)->
value = $(input).val()
split = input.selectionStart
@sub1 = value.substring(0, split).replace /\d*$/, (match) =>
@firstDigit = match
''
@firstDigit
Wonder if there is a way to keep firstDigit in the scope of the initValue function like this:
initValues: (input)->
value = $(input).val()
split = input.selectionStart
@sub1 = value.substring(0, split).replace /\d*$/, (match) ->
firstDigit = match
''
firstDigit
Declare it outside the callback function:
Demo: http://jsfiddle.net/ambiguous/uRFNq/
You might want to use a different name than
firstDigitthough asfirstDigitwon’t necessarily contain the first digits in the string, it will contain the trailing digits.