jquery入口函数的测试

/*编写一个自定义的jquery框架*/

(function (window,undefined) {
var njquery=function (selector ,) {
return new jquery .prototype.init(); /*prototype==fn*/
};
jquery.prototype={
constructor:njQuery
};

njquery.prototype.init.prototype=njquery.prototype;
window.njquery=Window.$ = njquery;
})(window);

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>02-jquery入口函数实例测试</title>
</head>
<body>


<script src="jquery-1.12.4.js"></script>
<script>
//1传入‘’ null undefined NaN 0 false
//会返回一个空的jquery对象给我们;
// console.log($())
// console.log($(null))
// console.log($(undefined))
// console.log($(NaN))
// console.log($(0))
// console.log($(false))


// 2传入代码片段
//会将创建好的DOM元素存储到jquery对象中返回
console.log($("<p>hihihihihi</p>"))
// 3传入选择器
// 会将找到的所有元素存储到jquery对象中返回
console.log($("li"))
// 4传入数组
// 会将数组中存储的元素依次存储到jquery对象中返回
console.log($([1,2,3,4,5]))
// 5传入伪数组
// 会将数组中存储的元素依次存储到jquery对象中返回
var likeArr={0:"lnj",1:"sda",2:'asd'}
console.log($(likeArr));
// 6传入对象值
// 会将传入的对象存储到jquery对象中返回
function Person() {}
console.log($(new Person()));

// 7传入DOM元素
// 会将传入的DOM元素存储到jquery对象中返回,
console.log($(document.createElement('div')));
//8 传入基本的数据类型
// 会将传入的基本数据类型存储到jquery对象中返回,
console.log($(123));
console.log($(true));

/*
*
* 结论: //1传入‘’ null undefined NaN 0 false 返回空的jquery对象
* 2字符串
* 3数组
* 4除上述类型以外
* */
</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/Damocless/p/11917039.html