首页 > Web开发 > 详细

对于jquery实现原理的浅谈

时间:2016-01-22 18:02:36      阅读:147      评论:0      收藏:0      [点我收藏+]

关键词: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>

 红色部分的代码可以看出代码风格为类的思想

对于jquery实现原理的浅谈

原文:http://www.cnblogs.com/wbjgogogo/p/5151554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!