/** * Generate a static keys string from compiler modules.//从编译器生成一个静态键字符串模块。 */ function genStaticKeys (modules) { return modules.reduce(function (keys, m) { return keys.concat(m.staticKeys || []) }, []).join(',') } /** * Check if two values are loosely equal - that is, * if they are plain objects, do they have the same shape? *///检查两个值是否相等 function looseEqual (a, b) { var isObjectA = isObject(a); var isObjectB = isObject(b); if (isObjectA && isObjectB) { return JSON.stringify(a) === JSON.stringify(b) } else if (!isObjectA && !isObjectB) { return String(a) === String(b) } else { return false } } //获取val在arr中的位置 function looseIndexOf (arr, val) { for (var i = 0; i < arr.length; i++) { if (looseEqual(arr[i], val)) { return i } } return -1 } /** * Ensure a function is called only once.//保证函数只执行一次 */ function once (fn) { var called = false; return function () { if (!called) { called = true; fn(); } } }