ant - javascript TypeError: Cannot find function startsWith -


i have javascript function:

           string.prototype.startswith = function(str) {                return (this.indexof(str) === 0);            } 

and when run on typeof returns object, works. when run on typeof returns string, get:

javax.script.scriptexception: sun.org.mozilla.javascript.internal.ecmaerror: typeerror: cannot find function startswith. (<unknown source>#29) in <unknown source> @ line number 29

does know whats going on? don't understand why instance type of first thing i'm using object. it's result of readline call, shouldn't string?

<target name="analyze">     <script language="javascript">      <![cdata[             importclass(java.io.file);             importclass(java.io.filereader)             importclass(java.io.bufferedreader)             //setup source directory             dir = project.getproperty("project_home");             fs = project.createdatatype("fileset");             fs.setdir(new file(dir));             //only analyze java files             fs.setincludes("**/*.java");             echo = project.createtask("echo");             //iterate on files found             srcfiles = fs.getdirectoryscanner(project).getincludedfiles();             (i = 0; < srcfiles.length; i++) {                 var filename = srcfiles[i];                 infile  = new bufferedreader(new filereader(new file(dir + "/" + filename)));                 while ((line = infile.readline()) != null) {                    if(line.startswith("package")) {                        packagestr = line.substr(8);                        while((line = infile.readline()) != null) {                            if(line.startswith("import") && line.endswith("foo;")) {                                //strip out leading import in 'import x.y.z'                                var importstr = line.substr(7);                                importstr = importstr.substr(0, importstr.lastindexof('.'));                                if(!importstr.startswith(packagestr)) { <---- fails!                                }                            }                        }                    }                 }                 infile.close();            }             string.prototype.startswith = function(str) {                return (this.indexof(str) === 0);            }             string.prototype.endswith = function(str) {                var lastindex = this.lastindexof(str);                return (lastindex != -1) && (lastindex + str.length == this.length);            }      ]]>     </script> </target> 

i think problem call starstwith function before define it. perhaps should put 2 function definitions ahead of for block. in way evaluated before called.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -