+ Now let's look at object creation. In Ruby you use the <ClassName>.new syntaxt to create a new instance of a class. In javascript, there are two ways of declaring a class. You can either use the object literal notation, or you can use the class constructor notation. Although they both use the word "new", they mean different things in each language. In Ruby, "new" is a method of the class object, whereas in javscript, "new" is a keyword of the language itself. In Ruby, calling "new" executes the code in the "initialize" method, whereas in javascript, everything inside the function constructor gets executed. Additionally, in javascript, calling "new" does some fancy things with binding the scope of "this" to the object itself. Ruby does have a "self" variable which also gets binded to the class object. However, the scoping rules in javascript are a bit more complex than in Ruby.
0 commit comments