var domFactories = ['div', 'a', 'span', 'label', 'input', 'select', 'i', 'p', 'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'hr', 'br'];
var DOM = {};
each(domFactories, function(element) {
DOM[element] = createElement.bind(null, element);
})
在helper.js中,這段函數(shù)報錯
helper.js
(function() {
// 使瀏覽器支持:scope選擇器
var container = document.createElement('div');
// 檢測瀏覽器是否支持:scope選擇器
try {
container.querySelectorAll(':scope *');
} catch (e) {
// :scope正則
var scopeReg = /^\s*:scope/gi;
function overrideSelector(method) {
var prototype = Element.prototype;
var oldMethod = prototype[method];
prototype[method] = function(selector) {
var nodeList;
var tempId = false;
var tempContainer = false;
if (!selector.match(scopeReg)) {
// 沒有使用:scope選擇器
return oldMethod.call(this, selector);
}
selector = selector.replace(scopeReg, '');
// 沒有父級元素,給它臨時生成一個
if (!this.parentNode) {
container.appendChild(this);
tempContainer = true;
}
var parentNode = this.parentNode;
// 沒有ID, 臨時給一個
if (!this.id) {
this.id = 'scopeQuerySelectorTempId' + (new Date()).getTime();
tempId = true;
}
// 用原生方法查找元素
nodeList = oldMethod.call(parentNode, '#' + this.id + ' ' + selector);
// 刪掉臨時ID
if (tempId) {
this.id = '';
}
// 從臨時的父級節(jié)點(diǎn)中刪除
if (tempContainer) {
container.removeChild(this);
}
// 返回匹配結(jié)果
return nodeList;
}
}
// 重寫querySelector和querySelectorAll方法
overrideSelector('querySelector');
overrideSelector('querySelectorAll');
}
})();
const Helper = {
/**
* 判斷是不是一個DOM對象
*
* @param {*} obj 要判斷的對象
* @return {boolean} 是否是DOM對象
*/
isDom(obj) {
return obj instanceof HTMLElement || obj instanceof Text;
},
/**
* 判斷是否是數(shù)組
*
* @param {*} obj 要判斷的對象
* @return {boolean} 是否是數(shù)組
*/
isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
},
/**
* 判斷是否是對象
*
* @param {*} obj 要判斷的對象
* @return {boolean} 是否是對象
*/
isObject(obj) {
return !(Object.prototype.toString.call(obj) !== '[object Object]' || isDom(obj) || obj instanceof Window);
},
/**
* 判斷是否是字符串
*
* @param {*} obj 要判斷的對象
* @return {boolean} 是否是字符串
*/
isString(obj) {
return typeof obj === 'string';
},
/**
* 判斷是否是函數(shù)
*
* @param {*} obj 要判斷的對象
* @return {boolean} 是否是函數(shù)
*/
isFunction(obj) {
return typeof obj === 'function';
},
/**
* 回調(diào)一個函數(shù),最后一個參數(shù)為context
*
* @param {Function} callback 回調(diào)函數(shù)
* @return {*} 返回回調(diào)函數(shù)返回的結(jié)果
*/
caller(callback) {
var args = arguments;
var context = args.length === 1 ? null : args[args.length - 1];
var params = Array.prototype.slice.call(args, 1, args.length);
if (isFunction(callback)) {
return callback.apply(context, params);
}
},
/**
* 遍歷一個對象或數(shù)組
*
* @param {Array|Object} obj 對象或數(shù)組
* @param {Function} fn 回調(diào)函數(shù)
*/
each(obj, fn) {
if (!(obj && fn)) {
return;
}
// 優(yōu)先使用forEach,針對數(shù)組
if (obj.forEach && isFunction(obj.forEach)) {
obj.forEach(function(item, i) {
caller(fn, item, i, item);
});
}
else if (obj.length === +obj.length) {
for (var i = 0, len = obj.length; i < len; i++) {
var item = obj[i];
caller(fn, item, i, item);
}
}
else
{
// 遍歷對象
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
caller(fn, obj[key], key, obj[key]);
}
}
}
},
var domFactories = ['div', 'a', 'span', 'label', 'input', 'select', 'i', 'p', 'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'hr', 'br'];
var DOM = {};
each(domFactories, function(element) {
DOM[element] = createElement.bind(null, element);
})
}
export default Helper
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。