为什么有的.js文件里面开始就是语句?js高手进
来源:百度知道 编辑:UC知道 时间:2024/05/27 08:29:58
为什么有的.js文件里面开始就是语句?而没有用function开头呢?比如:
if (!Object.prototype.toJSONString) {
Array.prototype.toJSONString = function (w) {
var a = [], // The array holding the partial texts.
i, // Loop counter.
l = this.length,
v; // The value to be stringified.
这是json的文件,我不明白怎么上来她就用if 语句
if (!Object.prototype.toJSONString) {
Array.prototype.toJSONString = function (w) {
var a = [], // The array holding the partial texts.
i, // Loop counter.
l = this.length,
v; // The value to be stringified.
这是json的文件,我不明白怎么上来她就用if 语句
它在最外层,自然就是js文件一加载完成就立即执行的语句。
这段代码就是当所有对象(Object)没有原型属性toJSONString时,为Array添加一个toJSONString的原型属性,供其他js函数调用。
那意思就是一加载这个js文件,就会立即执行这段代码啊
,还好