JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<!-- disregard this pane, html is shown in the "result" pane -->
<h4><strong>← Code Example from <a href="http://www.javascriptenlightenment.com/" target="_blank">JavaScript Enlightenment Book</a> by <a href="http://www.codylindley.com" target="_blank">Cody Lindley</a></strong></h4>
<p>JavaScript code is executed on page load. Click the "Run" button in the top bar to re-run the JavaScript code. Output is logged to the <a href="http://getfirebug.com/firebuglite" target="_blank">Firebug Lite</a> console below ↓.</p>
JavaScript
// 後でPerson()オブジェクトを生成するために、Personコンストラクタ関数を定義
var Person = function(living, age, gender) {
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function() { return this.gender; };
};
// Personオブジェクトをインスタンス化し、cody変数に格納する
var cody = new Person(true, 33, 'male');
console.log(cody);
/* JavaScript言語であらかじめ定義されているString()コンストラクタ関数も上記と同様のオブジェクトの生成パターンを持っています。String()の場合コンストラクタ関数はJavaScriptにビルトインされているため、インスタンス化を行うだけで文字列インスタンスを得ることができます。しかし組み込みのコンストラクタ関数を使おうが、Person()のようなカスタムコンストラクタ関数を使おうが、オブジェクトの生成パターンは同じです。 */
// 文字列オブジェクトをインスタンス化し、myString変数に格納
var myString = new String('foo');
console.log(myString);
//文字列オブジェクトをインスタンス化し、変数にmyStringに格納
var myString = new String('foo');
console.log(myString);