优化 lay 构造器,以适配选择器为自身对象的情况

pull/1220/head
贤心 2023-03-27 12:24:32 +08:00
parent 8de9a9c043
commit 365b159a18
1 changed files with 8 additions and 5 deletions

View File

@ -12,12 +12,15 @@
return new LAY(selector);
}
//DOM构造器
// DOM 构造器
,LAY = function(selector){
var index = 0
,nativeDOM = typeof selector === 'object' ? [selector] : (
this.selector = selector
,document.querySelectorAll(selector || null)
var index = 0;
var nativeDOM = typeof selector === 'object' ? function(){
// 仅适配简单元素对象
return layui.isArray(selector) ? selector : [selector];
}() : (
this.selector = selector,
document.querySelectorAll(selector || null)
);
for(; index < nativeDOM.length; index++){
this.push(nativeDOM[index]);