关于jQuery 1.4的发行说明,我来了acrosss $.noop(),它是:
描述:一个空函数.(在1.4中添加)
当你希望传递一个什么都不做的函数时,可以使用这个空函数.
也许我在这里遗漏了一些深刻的东西,但究竟是什么实际使用传递空函数?
代码示例赞赏.
我有一个类,用户可以将Action传入(或不传递).
public class FooClass<T> : BaseClass<T>
{
public FooClass()
: this((o) => ()) //This doesn't work...
{
}
public FooClass(Action<T> myAction)
: base(myAction)
{
}
}
Run Code Online (Sandbox Code Playgroud)
Action.但是,与此同时,我不想强迫我的用户传入Action.相反,我希望能够动态创建"无所事事"动作. 我需要将配置文件的多个部分转换为字典.这些词典的值有不同的类型.以下两个类可以工作,但它们几乎完全相同:
public class IntConfigSection
{
private static readonly ILog Log = LogManager.GetLogger(typeof(IntConfigSection));
public static Dictionary<String, int> LoadSection(string sectionName)
{
var ret = new Dictionary<String, int>();
try
{
var offsetsHash = (Hashtable)ConfigurationManager.GetSection(sectionName);
foreach (DictionaryEntry entry in offsetsHash)
{
ret.Add((String)entry.Key, int.Parse((String)entry.Value));
}
}
catch(Exception e)
{
Log.ErrorFormat("LoadSection:" + e);
}
return ret;
}
}
public class StringConfigSection
{
private static readonly ILog Log = LogManager.GetLogger(typeof(StringConfigSection));
public static Dictionary<String, String> LoadSection(string sectionName)
{
var ret = new Dictionary<String, String>();
try
{
var offsetsHash …Run Code Online (Sandbox Code Playgroud) c# ×2
action ×1
delegates ×1
javascript ×1
jquery ×1
jquery-1.4 ×1
lambda ×1
no-op ×1
refactoring ×1
templates ×1