Thank you for your answer, code examples and useful links. I know about module patter and saw it in many places but still never used it by myself.
So it will solve two of my problems: private method and referencing window object. Question about module patter: is it only one solution? After ES5 any other patterns appeared that can solve similar problem with private members? One point that I like in Object.defineProperty - is better control. E.x. if my method isn't writable than it cannot be override like fs.prototype.readAsText=function(..){ //new implementation } In case of module patter I think I don't have such control. E.x. I wan't people extend my fs object but doesn't change any of the methods. What technique to use for this? In what cases you use Object.defineProperty()? Question about testing remain: do you have any suggestions / links how to better do this? P.S. Also I didn't restrict myself to use ES5, since main use of this code in Chrome Web App that can be used using Chrome and I think Chrome supports ES5. But I'll try to make it work in another browsers with File API support. Best regards, Anton Podviaznikov >> if (global.requestFileSystem) I understand about feature detection. Thank you! On Feb 1, 3:42 am, RobG <rg...@iinet.net.au> wrote: > 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