So You Want to be a Functional Programmer (Part 2)
Charles Scalfani
2.3K31
it looks like those functions will miss their context:
var parseSsn = /^\d{3}-\d{2}-\d{4}$/.exec;
var parsePhone = /^\(\d{3}\)\d{3}-\d{4}$/.exec;phasePhone(‘whatever’)
=> TypeError: Method RegExp.prototype.exec called on incompatible receiver undefined
which can be solved with a bind:
var { exec } = Regex.prototype
var parseSsn = exec.bind( /^\d{3}-\d{2}-\d{4}$/);
var parsePhone = exec.bind(/^\(\d{3}\)\d{3}-\d{4}$/);