With MetaDOM style I wrote a little function to add runtime external scripts, this time compatible with all modern browser ;) This function is similar with Python import syntax, using From to specify a folder, or why not an uri, Import to add one or more script and finally an optional And method to call a callback on scripts loaded. Here You can view an example From("jsFolder") . Import("MyScript", "MyOhterScript") Seems cool? The first goal is to add dynamically one or more script in a simple and fast way. These script will be available on onload event if they're imported before this event. These scripts should be available on DOMContentLoaded too, but to be sure these script will be available You could add a callback using last method. From("jsFolder") . Import("MyScript", "MyOhterScript") . And(DoStuff) DoStuff is a function that do something with loaded scripts. What else You should do? You could load different ext...
JavaScript constructors (call them classses if You prefere) have some problem with private parameters or private methods. To use a private parameter You should simply use a variable without this as scope prefix function MyConstructor(){ this.getPrivate = function(){ return private; }; var private = "something"; }; It's simple and it works perfectly. Any external scope could get directly private variable and You can know its value only calling getPrivate method. var obj = new MyConstructor; alert(obj.getPrivate()); The cool thing is that if You change externally returned value it will not be changed inside object too but please remember that if You change them and it's a generic object or an array, these changes will be valid inside object scope too (object and arrays are sent by reference, You need to clone or copy them before to return them externally). Well, this is just a private parameters introduction and this is not useful if You write only using prototype ...
Comments
Post a Comment