vue.js源碼學習分享(一)

來源:互聯網
上載者:User

標籤:blog   whether   persist   寫部落格   span   move   typeof   indexof   json   

今天看了vue.js源碼  發現非常不錯,想一邊看一遍寫部落格和大家分享

/** * Convert a value to a string that is actually rendered.
 *轉換一個值為字串 */function _toString (val) { return val == null? ‘‘: typeof val === ‘object‘? JSON.stringify(val, null, 2): String(val)
//如果該值是null則返回Null 字元串,如果該值為對象,則返回json字串,否則把對象的值轉化為字串
//知識點:JSON.stringify(val, null, 2),String(val)
} 

  

/** * Convert a input value to a number for persistence. * If the conversion fails, return original string.轉化一個輸入值為一個數字,如果轉換失敗,則返回原始的字串
*/function toNumber (val) { var n = parseFloat(val); return isNaN(n) ? val : n//判斷n是不是 不是數字,如果不是數字則返回字串,如果是則返迴轉換好的數字}

 
/**
* Remove an item from an array//從數組刪除一個元素
*/
function remove (arr, item) {
if (arr.length) {
var index = arr.indexOf(item);//擷取元素的位置
if (index > -1) {//如果元素存在
return arr.splice(index, 1)//從數組中刪除並且返回這個元素
}
}
}

/**
* Check whether the object has the property.//檢查對象中是否有這個屬性
*/
var hasOwnProperty = Object.prototype.hasOwnProperty;//從對象的原型中擷取hasOwnProperty這個方法

function hasOwn (obj, key) {
  return hasOwnProperty.call(obj, key)
}
 

 

vue.js源碼學習分享(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.