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 = function(){alert("o1");};
    o2 = function(){alert("o2");};
    o2.prototype = new o1;
    var t11= new o2;

==============

function People(name)
{
this.name=name;
//对象方法
this.Introduce=function(){
alert("My name is "+this.name);
}
}
//类方法
People.Run=function(){
alert("I can run");
}
//原型方法
People.prototype.IntroduceChinese=function(){
alert(" 我的名字是"+this.name);
}

var p1=new People("Windking");
p1.Introduce();
People.Run();
p1.IntroduceChinese();

 

===================

function a(){
 var i=0;
 function b(){
 alert(++i);
 }
 return b;
}

var c=a();
c();
c();

 

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

var sURL = "http://oreilly.com/this_is_a_value&some-value='some value'";
sURL = encodeURI(sURL);
alert("<p>" + sURL + "</p>");
转换URL decodeURI转成正常字符
encodeURIComponent和decodeURIComponent,它们也能编码&、+和=,所以可以用于Ajax操作。

 

 

=================

alert(test123==null);
var test123;
alert(test123==undefined);

 

============
true
true
================

var test123=new Array(1,2,3);
for(var a in test123){
 alert(a);
}

 

0,1,2
===============

 var sTemp = "test string";
 alert ((typeof sTemp)+ " "+(typeof 86)+ " "+(typeof null)+ " "+(typeof undefined)+ " "+(typeof true)); //typeof null==object...

 

==================

   switch($("#input").val()){//switch可以用字符串
    case "0":
     alert("123");
     break;
   }

 

==============================

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值