日期:2014-05-16  浏览次数:20357 次

javascript笔记

q1:Extends是干嘛的??
q2:

//test
function ArgTest(a, b){
   var i, s = "The ArgTest function expected ";
   var numargs = arguments.length;     // 获取被传递参数的数值。
   var expargs = ArgTest.length;       // 获取期望参数的数值。
   if (expargs < 2)
      s += expargs + " argument. ";
   else
      s += expargs + " arguments. ";
   if (numargs < 2)
      s += numargs + " was passed.";
   else
      s += numargs + " were passed.";
   s += "\n\n"
   for (i =0 ; i < numargs; i++){      // 获取参数内容。
   s += "  Arg " + i + " = " + arguments[i] + "\n";
   }
   return(s);                          // 返回参数列表。
}

alert(ArgTest(3, 14));

?====================
arg:a
arg:b
====================

jquery

$("<option>",{
    value:  this.value,
    text:  this.text,
    selected: this.value==val ? true : false
   }) //属性添加方式

 function ClassA()
  {
     this.a='a';
 }
 function ClassB()
  {
     this.b='b';
 }
 ClassB.prototype=new ClassA();
 var objB=new ClassB();
 var info="";
 for(var p in objB) info += p+" ";
 alert(info);

??

====================
a b
===================

function ClassA()
  {
     this.a='a';
 }
 function ClassB()
  {
     this.b='b';
 }
 ClassB.prototype=new ClassA();
 var objB=new ClassB();
 alert(objB.a);
 ClassB.prototype.a='changed!!';
 alert(objB.a);

?

?

==============
a->changed
===================
?

 function ClassA()
  {
      this.a=function(){alert();};
 }
 function ClassB()
  {
      this.b=function(){alert();};
 }
 ClassB.prototype=new ClassA();
 var objB1=new ClassB();
 var objB2=new ClassB();
 alert(objB1.a==objB2.a);
 alert(objB1.b==objB2.b);

?

?

===================
true
false
=====================

function ClassA()
  {
     alert("a");
      this.a=function(){alert();};
 }
 function ClassB()
  {
     alert("b");
      this.b=function(){alert();};
 }
 ClassB.prototype=new ClassA();
 var objB1=new ClassB();
 var objB2=new ClassB();

?

?

===================
a
b
b
=====================

function ClassA()
  {
     this.a=[];
 }
 function ClassB()
  {
      this.b=function(){alert();};
 }
 ClassB.prototype=new ClassA();
 var objB1=new ClassB();
 var objB2=new ClassB();
 objB1.a.push(1,2,3);
 alert(objB2.a);//改1变2

?

===================
1,2,3
=====================

function A() { 
    this.t1 = "ffffff"; 
     this.t2 = function (msg) { 
         alert(msg); 
     }; 
 }; 
 A.prototype.p1 = "xxxx"; 
 A.prototype.f1 = function () { 
      alert(this.p1); 
 }; 
 
 var testtest=new A();
 testtest.t2("哇哈哈");
 testtest.f1();

?

===================
哇哈哈 xxxx
=====================

function AA(val1,val2) { 
     this.test1 = function() { 
         alert(val1); 
     }; 
 
     this.test2 = val2 ? function () { return this.test1;} : function () { return 456; }; 

     this.test3 = val1 ? val1 : function () {alert("no val1");}; 
 } 
 var t123=new AA(1,0);
t123.test1();
t123.test2();
t123.test3;//变量与函数并列,如果传回类型不同,会报错 找不到函数

?

==============
1
==================

function MyObject(name, size)
{
 this.name = name;
 this.size = size;
}
MyObject.prototype.color = "red";
MyObject.prototype.tellSize = function()
{
 return "size of "+this.name+" is "+this.size;
}
MyObject.prototype.tellColor = function()
{
 return "color of "+this.name+" is "+this.color;
}
var test1= new MyObject("123","10");
var test2= new MyObject("234","20");
test1.color = "white";
alert(test1.tellSize()+"\t"+test2.tellSize()+"\n"+test1.tellColor()+"\t"+test2.tellColor()+"\n"+test2.tellColor);

?

==================
??? o1 = functi