--- /dev/null
+/*MIT License*/\r
+
+Function.prototype.open = function() {\r
+ if (arguments.length === 0) {\r
+ throw new Error("no arguments error");\r
+ }\r
+ var that = this, // Callback Function\r
+ handle = [], // File Handler\r
+ fileNames = Array.prototype.slice.call(arguments),\r
+ fileName = fileNames.shift(),\r
+ xhr = new XMLHttpRequest();\r
+ handle.read = function () {\r
+ return this.join("\n");\r
+ };\r
+ handle.write = function (text) {\r
+ xhr.open("POST", fileName);\r
+ xhr.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");\r
+ xhr.send(text);\r
+ };\r
+ xhr.onreadystatechange = function() {\r
+ if (xhr.readyState === 4) {\r
+ if ((xhr.status === 200) || (xhr.status > 400)) {\r
+ var text = (xhr.status === 200) ? xhr.responseText : "";\r
+ handle.push((handle[fileName] = text));\r
+ if (fileNames.length !== 0) {\r
+ fileName = fileNames.shift();\r
+ f();\r
+ } else { //Load End\r
+ xhr.onreadystatechange = function() {}; //to solve the problem about a memory leak for IE 8\r
+ that(handle);\r
+ text = fileNames = xhr = handle = f = void 0;\r
+ }\r
+ }\r
+ }\r
+ };\r
+ var f = function() {\r
+ xhr.open("GET", fileName);\r
+ xhr.send();\r
+ };\r
+ f();\r
+};\r
+\r
+f.open("a.txt", "b.txt", "UNDEF.txt", "UNDEF.txt", "b.txt");\r
+\r
+function f (file) {\r
+ describe("File::open", function() {\r
+ it("for a read method", function() {\r
+ expect(file.read()).toEqual("1234\n5678\n\n\n5678");\r
+ expect(file["a.txt"]).toEqual("1234");\r
+ expect(file["b.txt"]).toEqual("5678");\r
+ expect(file[0]).toEqual("1234");\r
+ expect(file[1]).toEqual("5678");\r
+ expect(file["UNDEF.txt"]).toEqual("");\r
+ expect(file[2]).toEqual("");\r
+ expect(file[3]).toEqual("");\r
+ expect(file[4]).toEqual("5678");\r
+ });\r
+ });\r
+ __start_();\r
+};
\ No newline at end of file