对于jquery实现原理的浅谈

关键词:prototype(原型)。它能让javascript的方法(也可看成:类)能够动态地追加方法(猜测:目的是为了代码实现引入“类的思想”)

废话少说,代码见真义。

<html>
<head><title>prototype</title>
<script type="text/javascript">
var $ = function(){
if(window==this) return new $();
else
     return this;
     }
$.prototype = {
test:function(){
alert("test");
}
}
function vb(){
new $().test();
$().test();
alert($().test);
}
</script>
</head>
<body>
<button id="btn" onclick="vb()">prototype</button>
<div id="test">ttghfghg</div>
</body>
</html>

 方法体vb()的代码可以看出代码风格为类的思想

原文地址:https://www.cnblogs.com/wbjgogogo/p/5151554.html