Question: Is it possible to add methods to a `String` instance, for example

```
x = "123"
x.method = function() { console.log("test") }

x.method()

```

Answer: 
Yes, you can do it. You have to first take the string primitive and make it a string *instance*, though:

```
x = new String("123");
x.method = function() { console.log("test") };

x.method();

```

JavaScript has both string primitives and string instances. In your original code, when you wrote:

```
x.method = ...;

```

...the string primitive was retrieved from the variable `x` and promoted to a string instance, to which you added the method, but since the string *instance* was never stored back to the `x` variable, the method wasn't there when you tried to call it. (Yes, this *is* counter-intuitive.)

By using `new String(...)` in the above, I actually get the string instance and store it in `x`. Then, since it's a proper object, I can add properties to it.

You can also add methods to `String.prototype`, like this:

```
String.prototype.capitalize = function() {
    return this.substring(0, 1).toUpperCase() + this.substring(1);
};

console.log("testing".capitalize()); // "Testing"

```

Some feel this is bad practice. Others say it's exactly why we have prototypical inheritance, so we can use the prototype to enhance things. While I've never seen any problem from people enhancing `String.prototype`, I *have* seem problems when people enhance `Array.prototype` (because people insist on [misuing `for-in`](http://blog.niftysnippets.org/2010/11/myths-and-realities-of-forin.html)) and `Object.prototype`.
You could define new properties using ECMA5

```
Object.defineProperty(String.prototype, "test", {
value: function test() { console.log('test:',this) },
  configurable: true,
  enumerable: false,
  writeable: true
});

```

See the complete answer:
[Extending core types without modifying prototype](https://stackoverflow.com/questions/7141734/extending-core-types-without-modifying-prototype)