<commit_before>---
layout: post
title: JavaScript Objects
tags:
- javascript
---

Some things about JavaScript objects.


## Basic objects
There are some different ways you can create JavaScript objects, each having their own purposes and benefits.
<script src="https://jsfiddle.net/lthr/6ppb41eq/1/embed/js,result/"></script>

## Object constructors
If we want to create multiple instances of an object, we can use object constructors to define a template. By convention, constructors are named with a capital letter.
<script src="https://jsfiddle.net/lthr/qz6dq6t2/5/embed/js,result/"></script>

### The _new_ keyword
As you can see, the object constructor is just a normal function. However, the important part is the _new_ keyword, used when creating a new object instance of the constructor, which then returns the instance. Without it, you'll have a normal function, which returns nothing (actually, _undefined_), and sets the constructor properties on the window object (overwriting any window property of the same name).
<script src="https://jsfiddle.net/lthr/cg4akrom/3/embed/js,result/"></script>

If you haven't included `'use strict'` in your file, you won't even get an error about this.

## Properties
A property on an object is more than just a name and a value. You can see those by using the property descriptor method.
<script src="https://jsfiddle.net/lthr/t5p3uus8/1/embed/js,result/"></script>
<commit_msg>Update 2016-07-14-js-objects.md<commit_after>---
layout: post
title: JavaScript Objects
tags:
- javascript
---

Some things about JavaScript objects.


## Basic objects
There are some different ways you can create JavaScript objects, each having their own purposes and benefits.
<script src="https://jsfiddle.net/lthr/6ppb41eq/1/embed/js,result/"></script>

## Object constructors
If we want to create multiple instances of an object, we can use object constructors to define a template. By convention, constructors are named with a capital letter.
<script src="https://jsfiddle.net/lthr/qz6dq6t2/5/embed/js,result/"></script>

### The _new_ keyword
As you can see, the object constructor is just a normal function. However, the important part is the _new_ keyword, used when creating a new object instance of the constructor, which then returns the instance. Without it, you'll have a normal function, which returns nothing (actually, _undefined_), and sets the constructor properties on the window object (overwriting any window property of the same name).
<script src="https://jsfiddle.net/lthr/cg4akrom/3/embed/js,result/"></script>

If you haven't included `'use strict'` in your file, you won't even get an error about this.

## Properties
A property on an object is more than just a name and a value. You can see those by using the property descriptor method.
<script src="https://jsfiddle.net/lthr/t5p3uus8/2/embed/js,result/"></script>

{'fraction_non_alphanumeric': 0.09296657381615599, 'fraction_numerical': 0.012534818941504178, 'mean_word_length': 4.689108910891089, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '903352', 'n_tokens_mistral': 818, 'n_tokens_neox': 775, 'n_words': 359}