On Feb 1, 3:32 am, Anton Podviaznikov <podviazni...@gmail.com> wrote:
> Hello everybody. This is my first post in this group.
>
> I'm learning JavaScript and as almost everybody decided to write small
> library. My library is kind of wrapper for the HTML (5) File API.

The opening lines of fs.js:

| "use strict";
| var fs = Object.create({},

I don't know why you chose ECMAScript ed 5, but it's not well
supported. In Firefox 3.6:

  alert(typeof Object.create); // undefined

Are you using features that require ECMAScript ed 5? You can emulate
private members using the module pattern, rather than relying on
underscores to indicate them.


>
> It is not complete and it's not for production. I used it just in
> Chrome Web App.
>
> I'm interested in some feedback (not for the library itself) for the
> code. If you can quickly point me to some big error or make
> suggestions it would be very helpful for me.
>
> Also I have few questions:
> 1. I wanted few of my method be private. I know there are some
> patters, but what is the best in my case? Do you have any quick link?

I think the module pattern is the most commonly used:

<http://yuiblog.com/blog/2007/06/12/module-pattern/>

It is often attributed to Douglas Crockford, however it was developed
primarily by Richard Cornford and others. It is great if you only need
one of an object, but it can also be used to create a constructor.


> 2. I extended native FIle and FileError objects. Is it normal? Is it
> good style? How you will do this?

It is generally not a good idea to extend built-in objects. Is there a
significant advantage to doing it? If not, don't.


> 3. What is the better way to write tests for these kind of libs.
> 4. Is it ok that I reference to global window object?

It is considered better to establish an alias for the global object
and use that, e.g.

 var global = this;
 var fs = (function() {

    // Private members
    var _getNativeFS = {
        value: function(callback) {
            if (global.requestFileSystem) {
              global.requestFileSystem(window.PERSISTENT,
this.maxSize, function(fs) {
                ...
              });
            } else {
              // deal with not having global.requestFileSystem
            }
        }
    };

    ...

    return {

      // Public members
      log:
      {
          value: false,
          writable: true
      },
      ....

 })();

There are many resources on how to write libraries, fundamental
studies are the module pattern and feature or capability detection.
Peter Michaux[1] has blogged about quite a bit of it, so have others.

1. <URL: http://michaux.ca/ >


--
Rob

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to