1)コードを簡潔に記述できる
function putYourHeadInTheSand(otherFunc) {
try{
otherFunc();
} catch(e) { } // ignore the error
}
....
putYourHeadInTheSand(function(){
// do something here
});
putYourHeadInTheSand(function(){
// do something else
});
2)callback、非同期になる
Lets say you load some data somehow. Rather than locking up the system waiting for it to load, you can load it in the background, and do something with the result when it arrives.
function loadStuff(callback) {
// Go off and make an XHR or a web worker or somehow generate some data
var data = ...;
callback(data);
}
loadStuff(function(data){
alert('Now we have the data');
});
3)Lazy loading
まだ理解できていない
参考:https://stackoverflow.com/questions/2824393/javascript-function-as-a-parameter-to-another-function
2018年1月26日金曜日
C# (net framework 4.5以降) zip fileを扱う
using System;
using System.IO;
using System.IO.Compression; //このLibを使う
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
ちなみに、「@」を利用するとエスケープを行わずに「/」を文字列に含められるので、パスを指定したい場合などに可読性が高く、便利に使える。
using System.IO;
using System.IO.Compression; //このLibを使う
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
ちなみに、「@」を利用するとエスケープを行わずに「/」を文字列に含められるので、パスを指定したい場合などに可読性が高く、便利に使える。
2018年1月24日水曜日
C# delegate
A delegate is like a pointer to a function. It is a reference type data type and it holds the reference of a method.
delegate は代表の意味である。定義と同じ戻り値と引数を持つMethodを代入できる。
class Program
{
// declare delegate
public delegate void Print(int value);
static void Main(string[] args)
{
// Print delegate points to PrintNumber
Print printDel = PrintNumber;
printDel(100000);
printDel(200);
// Print delegate points to PrintMoney
printDel = PrintMoney;
printDel(10000);
printDel(200);
}
public static void PrintNumber(int num)
{
Console.WriteLine("Number: {0,-12:N0}",num);
}
public static void PrintMoney(int money)
{
Console.WriteLine("Money: {0:C}", money);
}
}
A method can have a parameter of a delegate type and can invoke the delegate parameter.
public static void PrintHelper(Print delegateFunc, int numToPrint)
{
delegateFunc(numToPrint);
}
delegate は代表の意味である。定義と同じ戻り値と引数を持つMethodを代入できる。
class Program
{
// declare delegate
public delegate void Print(int value);
static void Main(string[] args)
{
// Print delegate points to PrintNumber
Print printDel = PrintNumber;
printDel(100000);
printDel(200);
// Print delegate points to PrintMoney
printDel = PrintMoney;
printDel(10000);
printDel(200);
}
public static void PrintNumber(int num)
{
Console.WriteLine("Number: {0,-12:N0}",num);
}
public static void PrintMoney(int money)
{
Console.WriteLine("Money: {0:C}", money);
}
}
public static void PrintHelper(Print delegateFunc, int numToPrint)
{
delegateFunc(numToPrint);
}
参考:http://www.tutorialsteacher.com/csharp/csharp-delegates
2018年1月12日金曜日
vba Variantのnullとempty
値 Empty は、初期化されていない (初期値が代入されていない) Variant 変数を示します。
Null は、 Variant 変数に意図的に有効なデータが格納されていないことを示します。
Null は、 Variant 変数に意図的に有効なデータが格納されていないことを示します。
2017年12月25日月曜日
vba動的array
VBAで配列のサイズを指定しないと、エラーとなる
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
2017年12月12日火曜日
C# Array
int[] a1 = new int[10]; //10 elements
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
登録:
投稿 (Atom)