Scripting. FileSystemObject is a can implement the file read and write COM components, because COM components can be called across languages, so you can choose like VBS or JS such a script language call, I use the COM component to encapsulate a simple JS plug-in, the implementation of the file read and write function. (ie only open)
JS Code (plugin):
(function (win,undefined) {var fso = new ActiveXObject ("Scripting.FileSystemObject"); var file=null;var fileutil= function () {}; Fileutil.prototype={createtextfile:function (filename) {File=fso. CreateTextFile (filename, true);},write:function (content) {file. WriteLine (content);},closestream:function () {file=null;}} Win. Fileutil=fileutil;} (window))
The following begins the invocation of the component:
<! DOCTYPE html>
The effect of the implementation is as follows:
Although the code is relatively small, but it contains the writing JS plug-in the basic method and format, which used the JS closure. If we think deeply about plugins, our projects will be modular and component-developed, truly one-time development, and reuse everywhere.
JS Encapsulation Plug-in: Realize the file read and write function