關於我

我的相片
用心思考、保持熱情,把工作上的經驗作分享與紀錄。希望能夠跟大家一起不斷的成長~

JavaScript進階技巧

<%--進階JavaScript<1>物件方法屬性操作--%>
<script type="text/javascript">
  //委派Function?!   
  function say(msg) { alert(this.Name + ' 說:' + msg); }

  //建立物件
  var person = new Object();
  person.Name = "Sam";
  person.say = say;

  //取得屬性與呼叫方法
  alert("Name = " + person.Name);
  person.say("Hello !");

  //透過名稱字串呼叫方法與取得屬性
  alert("Name = " + person["Name"]);
  person["say"]("Hello !");
</script>

 

 

<%--進階JavaScript<2>匿名方法--%>
<script type="text/javascript">
  //建立物件
  var person = new Object();
  person.Name = "Peggy";
  //匿名方法設定方法
  person.say = function(msg) { alert(this.Name + ' 說:' + msg) };

  //取得屬性與呼叫方法
  alert("Name = " + person.Name);
  person.say("匿名方法耶 !");

  //透過名稱字串呼叫方法與取得屬性
  alert("Name = " + person["Name"]);
  person["say"]("匿名方法耶 !");
</script>

<%--進階JavaScript<3>匿名物件--%>
<script type="text/javascript">
  //建立匿名物件
  var person = {
    Name: "Peggy and Sam",
    say: function(msg) { alert(this.Name + ' 說:' + msg); }
  };

  //取得屬性與呼叫方法
  alert("Name = " + person.Name);
  person.say("匿名物件耶 !");

  //透過名稱字串呼叫方法與取得屬性
  alert("Name = " + person["Name"]);
  person["say"]("匿名物件耶 !");
</script>

Delegate,AnonymousDelegate,Func,LambdaExpression,Linq演化過程程式範例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestLambdaExpression2
{
  static class Program
  {
    static void Main(string[] args)
    {
      List allPerson = GetAllPerson();

      #region Func
      //1.
      Func FuncSelector = new Func(heightselector);
      Console.WriteLine(GetMaxFunc(allPerson, FuncSelector));

      //2.
      Func FuncSelector2 = heightselector;
      Console.WriteLine(GetMaxFunc(allPerson, FuncSelector2));

      //3.
      Console.WriteLine(GetMaxFunc(allPerson, heightselector)); 

      //4.
      Console.WriteLine(allPerson.GetMaxFunc(heightselector));

      //5.使用Lambda Expressions精簡Func之寫作
      Console.WriteLine(allPerson.GetMaxFunc(p => p.height));

      //6.因為Max為多型,必須先宣告形式才不會發生錯誤
      Func FuncSelector3 = heightselector;
      Console.WriteLine(allPerson.Max(FuncSelector3));
      #endregion


      #region Delegate
      //1.
      heightestSelector DelegateSelector = heightselector;
      Console.WriteLine(GetMaxDelegate(allPerson, DelegateSelector));

      //2.
      Console.WriteLine(GetMaxDelegate(allPerson, heightselector));

      //3.
      Console.WriteLine(allPerson.GetMaxDelegate(heightselector));

      //4.AnonymousDelegate
      Console.WriteLine(allPerson.GetMaxDelegate(delegate(Person p) { return p.height; }));

      //5.使用Lambda Expressions精簡AnonymousDelegate之寫作
      Console.WriteLine(allPerson.GetMaxDelegate(p => p.height));

      //6.會發生錯誤,因System.linq.Max需定義Func..不可傳入Delegate,會無法判定型式
      //heightestSelector DelegateSelector2 = heightselector;
      //Console.WriteLine(allPerson.Max(DelegateSelector2));

      //7.使用System.linq.Max,AnonymousDelegate
      Console.WriteLine(allPerson.Max(delegate(Person p) { return p.height; }));

      //8.使用System.linq.Max,Lambda Expressions精簡AnonymousDelegate之寫作
      Console.WriteLine(allPerson.Max(p => p.height));

      Man[] mans = Array.ConvertAll(allPerson.ToArray(), p => new Man() { name = p.name, weight = p.weight });
      Console.WriteLine(mans.Max(p => p.weight));
      #endregion

    }

    public delegate int heightestSelector(Person p);

    public static int heightselector(Person p) { return p.height; }

    private static int GetMaxFunc(this List allPerson, Func selector)
    {
      return (from i in allPerson
              select selector(i)).Max();
    }

    //private static decimal GetMaxFunc(this List allPerson, Func selector)
    //{
    //  return (from i in allPerson
    //          select selector(i)).Max();
    //}

    private static int GetMaxDelegate(this List allPerson, heightestSelector selector)
    {
      return (from i in allPerson
              select selector(i)).Max();
    }

    static List GetAllPerson()
    {
      List persons = new List();
      persons.Add(new Person { name = "A", height = 150, weight = 50 });
      persons.Add(new Person { name = "B", height = 160, weight = 60 });
      persons.Add(new Person { name = "C", height = 170, weight = 70 });
      persons.Add(new Person { name = "D", height = 180, weight = 80 });
      persons.Add(new Person { name = "E", height = 190, weight = 90 });
      return persons;
    }
  }

  public class Person
  {
    public string name { get; set; }
    public int height { get; set; }
    public int weight { get; set; }
  }

  public class Man
  {
    public string name { get; set; }
    public int weight { get; set; }
  }
}



windows FLP 安裝 Outlook Express方法

參考網址http://blog.yam.com/leo2016/article/14590189下方問與答 有人問,1. FLP是否有outlook express,如果沒有,是否可安裝? >>> 可安裝。 !!! 下面内容是參考韓國網頁(http://11cm2.tistory.com/174#comment2130637)我自己實習後寫的!!! 條件 1。FLP Full option install。 2。除了IE7和SP3之外,全部都window update。 安裝法 FLP安裝完之後, 1。Windows Explorer>Tools>Folder Options>View - 把所有隱藏的都設為顯示。 2。Windows\inf\msmail.inf Windows\inf\wab50.inf Windows\inf\msoe50.inf - 三個檔案按右建後安裝。 - 若問途徑就把一般的Win XP CD放進去,然後圖勁指定為i386檔案夾。 3。安裝完在Program files下面會看到Outlook express檔案夾。做個捷徑使用。 ** 這麽做就可以使用Outlook和POP3 Mail了。沒做這個動作就在Outlook上不能收發Mail。 ** 聽説,使用Office2007就不用這麽麻煩了。直接安裝就可以使用Outlook。 ** 祝你們internet life開心 ^^