Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Code Commenting. #3

nackjicholson opened this Issue Sep 23, 2011 · 3 comments


None yet
4 participants

Hey, Great book, I'm enjoying the hell out of it. Its pretty much exactly what I need to refine my javascript to the next level. However, I'm trying go through your examples here, and I'm dying because there isn't any code commenting. Brief comments to clarify what is happening would help immensely I think.

I'm on chapter 3 trying to wrap my head around the ORM and Model specifically and I can't seem to follow what's happening. Explanations of what and why you write what you write would improve these companion files in my opinion.

There is code comment in the Oreilly's book.

But the code on ch03/inherit.html does not work.

The thing is with:

create: function(){
    var object = Object.create(this);
    object.parent = this;
    object.init.apply(object, arguments);
    return object;


    init: function(){
    this.records = {};
    this.attributes = [];

because you have extended the class properties you now have on the newly created object prototype the "extended" init function.

When calling on an instance: Asset.init() it runs that function instead of the "included" one.

I guess you can't override the first init function on Model's object with the extended one. (that's why he uses the created function after running the create on Model's object).

mtomov commented Apr 12, 2013

There is indeed an error in the code of ch03/inherit.html.

"init" in the Model should be "inst", and the call at the end of the file should be to this "inst"

inst: function(){
  var instance = Object.create(this.prototype);
  instance.parent = this;
  instance.init.apply(instance, arguments);
  return instance;

var asset = Asset.inst();
asset.load({one: 1});

The code and explanations in the book are thereby also erroneous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment