This is a combination of how Array.prototype.filter is implemented and how javascript function declaration works.
Every function declaration has a local this reference that varies depending on how the function has been called. Take the this as the context of the function.
So, because Array.prototype.filter is unbound to a specific context, you can call it with a specific one, in this case it will be the sentence.
According to the spec, Array.prototype.filter function is implemented something like this:
Array.prototype.filter = function(callbackFn, thisArg){
var A = new Array();
var length = this.length;
for(var i=0; i<length; i++){
var el = this[i];
if(callbackFn.call(thisArg, el, i, this)){
A.push(el);
}
}
return A;
}
So it is only needed that the context has a length property and 0 to length - 1 properties, String has all of this so when calling Array.prototype.filter.call(string) the context of the function will be the string and it will loop over it.
Of course you can do(although not recommended):
String.prototype.filter = function(callback, thisArg){
return Array.prototype.filter.call(this, callback, thisArg)
}
So then you can just call:
sentence.filter(checkValue)