Instead of using
function functionName(arg){
arg = 1;
}
name(arg);
I want to use something like the .toUppercase() function
function functionName(){
this = 1;
}
arg.name();
Is this possible?
Instead of using
function functionName(arg){
arg = 1;
}
name(arg);
I want to use something like the .toUppercase() function
function functionName(){
this = 1;
}
arg.name();
Is this possible?
You can extend the prototype of the string object in JavaScript
String.prototype.functionName = function () {
return this; //do whatever you want to do it with the string
};
Now you are able to call this way mystring.functionName()
add function inside the object
var arg = {
name:function(str){
return str;
}
}
console.log(arg.name('sss'))