This is a javascript function:
String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};
How can I access the argument '14' in function while calling function like this:
'14'.digit();
You could use Object#valueOf method
The
valueOf()method returns the primitive value of the specified object.
String.prototype.digit = function() {
console.log(this.valueOf());
return false;
};
'14'.digit();
or Object#toString method.
The
toString()method returns a string representing the object.
String.prototype.digit = function() {
console.log(this.toString());
return false;
};
'14'.digit();
function(arg) { console.log(arg); }The keywordthisis not the argument but the object you are calling the function from.