vue.js源码学习分享(一)
生活随笔
收集整理的這篇文章主要介紹了
vue.js源码学习分享(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天看了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則返回空字符串,如果該值為對象,則返回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)
} ?
?
轉載于:https://www.cnblogs.com/liuhao-web/p/6669480.html
總結
以上是生活随笔為你收集整理的vue.js源码学习分享(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python - 字符串
- 下一篇: 实现vue2.0响应式的基本思路