最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue源碼中的檢測(cè)方法的實(shí)現(xiàn)

 更新時(shí)間:2019年09月26日 10:01:28   作者:夏小夏  
這篇文章主要介紹了vue源碼中的檢測(cè)方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

判斷是否為undefined或null

const isDef = (v) => {
 return v !== undefined && v !== null
}

判斷是否為Promise 函數(shù)

const isPromise = (val) => {
 return (
  val !== undefine &&
  typeof val.then === 'function' &&
  typeof val.catch === 'function'
 )
}

判斷是否為簡(jiǎn)單數(shù)據(jù)類型

const isPrimitive (value) => {
 return (
  typeof value === 'string' ||
  typeof value === 'number' ||
  typeof value === 'symbol' ||
  typeof value === 'boolean'
 )
}

嚴(yán)格檢查復(fù)雜數(shù)據(jù)類型

const isPlainObject = (obj) => {
 return Object.prototype.toString.call(obj) === '[object Object]'
}

const isRegExp = (v) => {
 return Object.prototype.toString.call(v) === '[object RegExp]'
}

將駝峰字符串轉(zhuǎn)成連接符 magicEightTall 轉(zhuǎn)換成 magic-eight-tall

const hyphenateRE = /\B([A-Z])/g
const hyphenate = (str) => {
 return str.replace(hyphenateRE, '-$1').toLowerCase()
}

將連接符轉(zhuǎn)成駝峰字符串 magic-eight-tall 轉(zhuǎn)換成 magicEightTall

const camelizeRE = /-(\w)/g
const camelize = (str) => {
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}

如果不想重復(fù)轉(zhuǎn)換,可用以下方法調(diào)用轉(zhuǎn)換函數(shù)

const cached = (fn) => {
  const cache = Object.create(null)
  console.log(cache);
  return ((str) => {
   const hit = cache[str]
   return hit || (cache[str] = fn(str))
  })
};


const camelize = cached((str) => {
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

宜都市| 会昌县| 和平区| 邵东县| 仲巴县| 博湖县| 高密市| 静海县| 苏州市| 沅江市| 固始县| 莱芜市| 普陀区| 山西省| 黑龙江省| 利津县| 德清县| 高平市| 民和| 贵南县| 贵阳市| 郑州市| 高碑店市| 深水埗区| 刚察县| 临武县| 武川县| 忻城县| 广西| 易门县| 瑞金市| 萨嘎县| 赤壁市| 花莲市| 扎兰屯市| 高台县| 绥宁县| 哈密市| 安义县| 伽师县| 斗六市|