5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

開眼!JavaScriptの2.1のまとめ オブジェクトへのプロパティの格納について

Last updated at Posted at 2015-04-10

開眼!JavaScriptの2.1のまとめです。

##2.1 オブジェクトはすべての値をプロパティとして格納できる
オブジェクトは、JavaScriptであらわすことができるすべての値を格納(もしくは参照)することができる。
String()、Number()、Boolean()の値でさえも、new演算子でオブジェクトとして生成されたのであれば同様の操作を行うことができる。

実際にString()、Number()、Boolean()を格納して出力

var myFunction = function(){};

myFunction.myString = new String();
myFunction.myString2 = new String("string");
myFunction.myBoolean = new Boolean();
myFunction.myBoolean2 = new Boolean(true);
myFunction.myNumber = new Number();
myFunction.myNumber2 = new Number(100);

console.log(myFunction.myString,myFunction.myString2,myFunction.myBoolean,myFunction.myBoolean2,myFunction.myNumber,myFunction.myNumber2);

結果(見やすいように改行しています)
String {length: 0, [[PrimitiveValue]]: ""}
String {0: "s", 1: "t", 2: "r", 3: "i", 4: "n", 5: "g", length: 6, [[PrimitiveValue]]: "string"}
Boolean {[[PrimitiveValue]]: false}
Boolean {[[PrimitiveValue]]: true}
Number {[[PrimitiveValue]]: 0}
Number {[[PrimitiveValue]]: 100}

5
5
0

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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?