我正在维护一些遗留代码,我注意到使用了以下用于定义对象的模式:
var MyObject = {};
(function (root) {
root.myFunction = function (foo) {
//do something
};
})(MyObject);
Run Code Online (Sandbox Code Playgroud)
这有什么用途吗?它只相当于做以下事情吗?
var MyObject = {
myFunction : function (foo) {
//do something
};
};
Run Code Online (Sandbox Code Playgroud)
我不打算采用神圣的方式将整个代码库重构为我的喜好,但我真的很想了解定义对象的迂回方式背后的原因.
谢谢!
我有以下类树:
public class A
{
public static object GetMe(SomeOtherClass something)
{
return something.Foo();
}
}
public class B:A
{
public static new object GetMe(SomeOtherClass something)
{
return something.Bar();
}
}
public class C:B
{
}
public class SomeOtherClass
{
}
Run Code Online (Sandbox Code Playgroud)
鉴于SomeOtherClass parameter = new SomeOtherClass())这工作:
typeof(B).GetMethod("GetMe", new Type[] { typeof(SomeOtherClass) })).Invoke(null, parameter));
Run Code Online (Sandbox Code Playgroud)
但是这个:
typeof(C).GetMethod("GetMe", new Type[] { typeof(SomeOtherClass) })).Invoke(null, parameter));
Run Code Online (Sandbox Code Playgroud)
抛出一个NullReferenceException,虽然我希望它会调用与上面完全相同的方法.
我试过几个绑定标志无济于事.有帮助吗?
如今大多数设备都允许自动切换暗/亮模式,但 Windows 10 似乎没有这样的功能。有办法做到这一点吗?例如使用任务计划程序?
似乎有很多关于如何以编程方式更改窗口“主题”的示例,但没有关于亮/暗模式切换的示例(可以在“设置/颜色”中为“Windows 模式”或“应用程序模式”独立设置)。
c# ×1
darkmode ×1
getmethod ×1
inheritance ×1
javascript ×1
methods ×1
powershell ×1
scheduler ×1
static ×1
windows-10 ×1