林中誠 動態網頁設計 20121129 作業一 林中誠 動態網頁設計 20121129 作業一
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Ch8_2_2.htm</title>
</head>
<body>
<h2>使用物件字面值建立物件方法</h2>
<hr/>
<script>
// 建立自訂物件
var objCard = {
  name : "陳小安",
  age  : 20,
  phone: "02-22222222",
  email: "hueyan@ms2.hinet.net",
  printCard: function() {
     document.write("姓名 : " + this.name + "<br/>");
     document.write("年齡 : " + this.age + "<br/>");
     document.write("電話 : " + this.phone + "<br/>");
     document.write("電郵 : " + this.email + "<br/>");
  }
};
// 呼叫物件方法
objCard.printCard();
</script>
</body>
</html>
 
 
 
 
  
 
 
 
 
 
 
網頁測試一 網頁測試一
Ch8_2_2.htm

使用物件字面值建立物件方法


Function Pointer Function Pointer

#include <stdio.h>
#include <stdlib.h>

int x=800,y=500;

void add(void)
{
    printf( "The result is %d\n",x+y);
}
void sub(void)
{
    printf( "The result is %d\n",x-y);
}
void mul(void)
{
    printf( "The result is %d\n",x*y);
}

void divi(void)
{
    printf( "The result is %d\n",x/y);
}

int main()
{
    void (*foo)(void); 
    void operation(void (*)(void));
    int choice;
    printf("enter your choice = "); 
    scanf("%d",&choice);   
    switch(choice) 
    {         
    case 1: operation(add); //implicit
             break;         
    case 2:operation(sub); 
             break; 
    case 3: operation(mul); 
            break; 
    case 4: operation(divi);           
             break;         
    case 5: exit(0);         
    default:printf("no such option\n"); 
    }     
  
    system("PAUSE");
    return 0;
}

void operation(void(*fooo)(void))

{
    fooo();

}

林中誠 動態網頁設計 20121129 作業二 林中誠 動態網頁設計 20121129 作業二

 <!DOCTYPE html>

<html>
<head>
<meta charset="utf-8"/>
<title>Ch8_3_2.htm</title>
<script> 
// JavaScript函數
function printCard() {
   document.write("姓名 : " + this.name + "<br/>");
   document.write("年齡 : " + this.age + "<br/>");
   document.write("電話 : " + this.phone + "<br/>");
   document.write("電郵 : " + this.email + "<br/><hr/>");
}
</script>
</head>
<body>
<h2>在自訂物件新增方法</h2>
<hr/>
<script>

var objCard = new Object();

objCard.name = "江小魚";
objCard.age = 20;
objCard.phone = "03-33333333";
objCard.email = "smallfish@yahoo.com.tw";

objCard.print = printCard;

objCard.displayName = function() {
   document.write("姓名 : " + this.name + "<br/>");
   document.write("年齡 : " + this.age + "<br/>");
   document.write("電話 : " + this.phone + "<br/>");
   document.write("電郵 : " + this.email + "<br/><hr/>");
}

objCard.print();
objCard.displayName();
</script>
</body>
</html>   

網頁測試二 網頁測試二
Ch8_3_2.htm

在自訂物件新增方法