日期:2014-05-16 浏览次数:20501 次
1.prototype,简单的理解应该是个父类指针.如果没父类就是指自己.
?
?
?
?
//声明一个对象child?
function Child(id){
this.id = id;
this.getId = function(){
return this.id;
}
}
function Base(name){
this.name = name;
this.getName = function(){
return this.name;
}
}
Child.prototype = new Base("base");
//实例化一个child对象
var c1 = new Child("child");
alert(c1.getName());
??
child可以显示Base的name
?
?
?
2.下面这个体(因为不像函数)很神奇.看了半天也没看懂.
?
?
(function(){
})();
?
其实它的意义就是为了定义一些非开放的方法,供在里面的开放方法使用.
?
var obj = {}
(function(){
function a() {
}
obj.prototype.alert = function (){
a();
}
})();
?
?
?
?
这里obj.alert()可以全局使用,但是a()就不能全局使用.
?
再来个经典的jquery变体
?
?
(function($){
$.fn.extend({
pluginName:function(opt,callback){
}
})
$.alert = function(){alert()}
})(jQuery);
?
?
将jQuery(实参)作为$(形参)代入function
?
?
?
?
jQuery扩展
共两种方式:
1
$.extend({
foo : function(){...}
})?
效果为 $.foo()
?
2
$.fn.extend({
foo : function(){...}
})
效果为 $('div').foo()
?
?
?
?
undefined null 区别
?
undefined 是 没有此对象和 对象没有值和引用,一般没有赋初始值造成.
?
null 是一个对象.
?
在判断中 ?undefined == null ?is true
?
一种生成function的方法
?
window['fun1']=function(data) {alert(data);}
调用方法 fun1('x');
?
一张调用function的方法
function fun1(){alert('a');}
fun1.call();
或者
var x = fun1;
x.call();
?
jquery ajax 事件顺序
ajaxStart
ajaxSend
ajaxComplete
ajaxSuccess
ajaxStop
?
js 对象
var a = {'a':'1'};
a['b']=2;
a.c=3;
以上三都是新建对象