What you are trying to do is called a type extension. There are such types of things in javscript as object type, array type, etc.
You can use a prototype to increase these built-in types, for example, by adding a new method that can be called for any object from an array of types:
Array.prototype.myNewMethod = function() {
Then you can call your method in any array:
[0,1,2].myNewMethod();
There is no INPUT type in JavaScript; DOM elements are classified as objects. But you could collect something, something like what you need, for example,
Object.prototype.changeValue = function(el) { if (el.tagName === "INPUT") { return "Mr " + el.value; } } var testEl = document.getElementById("test"); document.write(testEl.changeValue(testEl))
Used with this text box:
<input id="test" value="Dan" />
Then you get the output "Mr Dan"
However, this is not great, just to illustrate the point and this is just what you started ...
I made a violin so you can play with it
source share