I'm reading through AngularJS developer guidelines, and although I'm not so new to JavaScript, and although Google talks down to developers I don't understand some portions of the documentation.

Namely, I don't understand what hash object is. I thought I knew what object hash was, but they use it differently. I'll put few quotes to illustrate:

About scope parameter of $compile function

If set to {} (object hash), then a new "isolate" scope is created

The 'isolate' scope takes an object hash which defines a set of local scope properties derived from the parent scope. These local properties are useful for aliasing values for templates. Locals definition is a hash of local scope property to its source:

Talking about link function for creationg of directives

attrs is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values

  • What is a hash object? Is it just an ordinary object?
  • Is this term something often used in JavaScript development, or a habit of Angular developers?
  • If hash object is just an object, what other kinds of objects exist?
  • Are object hash and hash object same thing? If so, they should probably revise their documentation.

Comment to answers:

As I asked several questions, each answerer seems to have answered best to a single part. For future reference, each of them is valuable and worth the read.

有帮助吗?

解决方案 2

It is all the same.

To answer your questions in order:

  1. A hash object is just an object. In JavaScript, This can be written {} (sometimes called object literals) in the code. You can also create objects with a = new Object()if you want.

  2. The term is used. I personally did not notice the term hash object often, as JavaScript objects are usually just referred to as objects.

  3. In JavaScript, only objects (e.g. {} is an object) exist. You might know objects in other languages by different names: Dictionary, Hash, Associative Array, just to name a few. The essential thing to remember is that in JavaScript, an object is basically just a set of key-value-pairs (with a key of type String and an arbitrary value).

  4. Yes and yes.

I said "objects" a lot in this answer - it really is not that complicated as it's just multiple different names for the same thing..

其他提示

  1. Just ordinary object
  2. It's just object, so it's common thing.
  3. Functions-objects
  4. Yes. PR are welcome :) http://angularjs.org/i-want-to-help

What is a hash object? Is it just an ordinary object?

In JavaScript, objects are implemented as hash maps (some call them hash tables). "Hash object", "object hash" or just "object" seems to be used in the documentation inconsistently to refer to the same thing.

Is this term something often used in JavaScript development, or a habit of Angular developers?

Usually, you would just say "object" or "hash".

If hash object is just an object, what other kinds of objects exist?

In the context of Angular APIs, none other. It all refers to just plain "objects".

Are object hash and hash object same thing? If so, they should probably revise their documentation.

Exactly.

When they say hash, hash object, hash map, etc, all mean {key: 'value'} syntax. Obviously, value can be any JavaScript value. key can be named like a variable or a string.

But if they say just "object" this could mean a lot of different things because almost everything in JavaScript is an object.

From Mozilla Developer Network:

Object everything

In JavaScript, almost everything is an object. All primitive types except null and undefined are treated as objects. They can be assigned properties (assigned properties of some types are not persistent), and they have all characteristics of objects.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top