3
3

More than 5 years have passed since last update.

JavaScriptで文字列をObject.createするとTypeError、new Stringすると・・・

Last updated at Posted at 2013-12-17

GoogleChrome31で試しました。

Object.create

直接Object.createするとTypeErrorが起きます。

> Object.create("abc");
TypeError: Object prototype may only be an Object or null

new Stringすると・・・

> Object.create(new String("abc"));
String {0: "a", 1: "b", 2: "c"}

文字列化

ただし、文字列化しようとするとTypeErrorが起きます。

> String(Object.create(new String("abc")));
TypeError: String.prototype.toString is not generic

newしただけなら文字列化できます。

> String(new String("abc"));
"abc"
3
3
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3