Tag: 内联代码

编写内联事件处理程序是不好的做法

编写内联事件处理程序是不好的做法? 对于我来说,我更喜欢在事件处理程序中使用本地variables时使用它,如下所示: 我更喜欢这个: // This is just a sample private void Foo() { Timer timer = new Timer() { Interval = 1000 }; int counter = 0; // counter has just this mission timer.Tick += (s, e) => myTextBox.Text = (counter++).ToString(); timer.Start(); } 而不是这个: int counter = 0; // No need for this out of […]

在java中有内联函数吗?

在java中是否有内联函数的概念,或者被其他的东西replace了吗? 如果有,它是如何使用的? 我听说public , static和final方法是内联函数。 我们可以创build自己的内联函数吗?

onclick =“”与事件处理程序

如果我想要一个函数被执行,我更喜欢做内联js: <p id="element" onclick="doSomething();">Click me</p> 因为它更容易debugging。 但是,我听到有人说不要使用内联js,而是: document.getElementById('element').onclick = doSomething; 为什么推荐使用js事件监听器?