vue.js源码学习分享(三)

/**
 * Mix properties into target object.//把多个属性插入目标的对象
 */
function extend (to, _from) {
  for (var key in _from) {
    to[key] = _from[key];
  }
  return to
}

/**
 * Quick object check - this is primarily used to tell
 * Objects from primitive values when we know the value
 * is a JSON-compliant type.//检查是不是对象
 */
function isObject (obj) {
  return obj !== null && typeof obj === 'object'
}

/**
 * Strict object type check. Only returns true
 * for plain JavaScript objects.//严格的对象检查
 */
var toString = Object.prototype.toString;
var OBJECT_STRING = '[object Object]';
function isPlainObject (obj) {
  return toString.call(obj) === OBJECT_STRING
}

/**
 * Merge an Array of Objects into a single Object.//相当于复制一个数组
 */
function toObject (arr) {
  var res = {};
  for (var i = 0; i < arr.length; i++) {
    if (arr[i]) {
      extend(res, arr[i]);
    }
  }
  return res
}

/**
 * Perform no operation.无操作
 */
function noop () {}

/**
 * Always return false.//总是返回false
 */
var no = function () { return false; };

/**
 * Return same value//返回相同的值
 */
var identity = function (_) { return _; };

 

posted @ 2017-04-05 17:24  刘浩2561179983  阅读(297)  评论(0编辑  收藏  举报