前言:prototype的运用
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
</head>
<body>
姓名是:<span></span>
<script src="jquery.min.js"></script>
<script>
function sdh(option){
this.option=option;
this.init();
}
sdh.prototype={
init:function(){
this.getsex();
},
getsex:function(){
var me=this;
setTimeout(function(){
var student_name='Xiao Ming';
me.option.callback(student_name);
},1000)
}
}
$.fn.sdh=function(option){
return new sdh(option);
}
// 传入id,返回姓名
$('span').sdh({
id:12,
callback:function(name){
$('span').html(name);
}
})
</script>
</body>
</html>