亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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ù)類(lèi)型

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

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

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)論