[Javascript] Cheatsheet

Getting properties/keys of objects

Objects.keys(object_name) => returns an array of keys

for(var key in object_name){} => Iterates through the object

Javascript builder on Sublimetext

Use Mac OS X terminal as a javascript REPL

cd   // Go to home folder
// You need to folder to create a symlink. Here I make a folder called bin
mkdir .bin
cd .bin  // Go to bin folder
// Here I make a symlink to to jsc
ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc jsc
// Now add a .bin folder path
sudo nano /etc/paths
// There you add a path
User/user_name/.bin
// Now open a new terminal, you go to .bin folder and
./jsc
// Voila!

Use objects like a Python dictionary

var family_age = new Object()
family_age["mom"] = 32;
family_age["dad"] = 33;
family_age["son"] = 2;
family_age["daughter"] = 1;

family_age will look like:
{"mom": 32, 'dad': 33, 'son': 2, 'daughter': 1}
You can access items by using keys:
family_age['son']   // 2

Continue….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: