We want a function that can apply methods to the input object.
First, we create a function.
$ = function () { /* Constructor Code */ };
Then, we add a method. For example, type. The method will use this function:
function () { return toString.call(this).slice(8, -1);
Finally, we test the function to see if we get the right output. This is what we want to see:
$("test"); // Output: "test"
$("test").type(); // Output: "String"
$(document.body).type(); // Output: "HTMLBodyElement"
The only way the output should differ from the input is an application of methods.
Using Object.addProperties won't work, as it converts the input into an object:
$("test").type(); // Output: "Object"
Also, using an eval-related method won't work either, as some objects don't convert to strings:
$(document.body).type(); // Error: Can't convert element to string!
The same goes for adding an object's properties manually to the object.
$("test").type(); // Can't apply function to literal string!
The question is, what do we do?