005 JSJ Javascript Objects




Javascript Jabber show

Summary: Panel AJ O'Neal (twitter github blog) Charles Max Wood (twitter github Teach Me To Code Rails Summer Camp) Jamison Dance (twitter github blog) Joachim Larsen (g+ github website) Yehuda Katz (twitter github blog) Discussion Objects are basically hashmaps Calling 'new' Constructors Javascript creates an empty object and hands it off to the constructor Functions are sort of like classes ES5 (strict mode) arguments.callee Old SproutCore used arguments.callee to implement super Prototypes The new object inherits the function's prototype Prototypes are referenced, not copied Don't monkey with Object.prototype Should you override native prototypes? Object.keys vs for x in y Premature optimization Property iteration Namespaces es-discuss 3 paradigms new literals function newX() Object.create(prototype) (contributed by Yehuda in the backchannel) Data privacy jQuery uses the prototype system Don't be over obsessed with privacy Functions create closures Closures carry the context they were created in Scoped variables in closures are also referenced, not copied. So, changes to those variables are reflected to everything else in that scope. Closures can make memory management and scoping problems worse, but are generally a good thing Waterfall pattern: keep functions in the same scope/indentation level and call the next when one finishes Array syntax creates an object that inherits a specific prototype Object keys can only be a string How to think about OO EMCAScript 5 Objects and Properties Closure in action More issues with closures Add behaviors to objects or static clases with 'mix' Code example - Prototypeal Inheritance Understanding JavaScript Function Involcation and 'this' Picks Once Upon a Time (Yehuda) Pseudopod (Jamison) EloquentJavascript.net (Joachim) JSFiddle.net (Joachim) Carrabba's (AJ) Requiem (AJ) Heil PR-40 (Chuck) Shure SM-58 (Chuck) Blue Snowball (Chuck) XENYX 802 (Chuck) iMic (Chuck) Roland R-05 (Chuck) Adobe Audition (Chuck) Transcript CHUCK: We’re trying to maintain a clean rating, so if you can help it that will be nice. JOACHIM: All right, well I am naked. [Laughter] CHUCK: Aaaah! That’s like Avdi in his gold bikini. JOACHIM: Obviously I’m not just going to you know, blurt it out. JAMISON: I can actually hear that you are naked on the podcast. So you might wanna edit that. I can tell it through your voice. JOACHIM: I’ll eventually, hang on. JAMISON: Oh, gosh. [Laughter] CHUCK: Hey everybody, welcome to the JavaScript Jabber podcast. This is Episode 5. This week on our panel, we have AJ O’Neal. AJ: Hey, guys! CHUCK: We also have Yehuda Katz. YEHUDA: Hey, hey. CHUCK: We have Jamison Dance. JAMISON: My name is Jamison Dance and I have a problem. CHUCK: [Chuckles] JAMISON: Oh, wrong podcast. Hi. CHUCK: And we also have Joachim Larsen. JOACHIM: Hey all. CHUCK: And I’m Charles Max Wood from teachmetocode.com. Real quick, I've been accused of not letting people know that I have other podcasts, so I’m just going to tell you really quickly; we also do rubyrogues.com that’s the Ruby Rogues podcast, where we talk about Ruby; and rubyfreelancers.com where we talk about freelancing -- same format as this one. So anyway, this week we are going to be talking about “Objects in JavaScript,” which is kind of not as straightforward as you might think or want it to be. And since I’m not the expert here, I’m going to let somebody else go ahead and jump in and start us out. AJ: What do you wanna know? CHUCK: [Chuckles] Well, okay so— JAMISON: Everything. CHUCK: Okay so basically, I've been reading ‘JavaScript: The Good Parts’ and so the first thing he talks about is your general objects which most people kind of equate to do a dictionary or a hash, but it’s not exactly the same thing.