有什么利弊?
是否有针对此案的共识或良好做法?
有什么说明这些工具,代码约定和标准指南?
Page p;
private void Button_Click_1(object sender, RoutedEventArgs e)
{
p = (Page) Application.LoadComponent(new Uri("Views/EmployeeDetaiView.Xaml.xaml", UriKind.Relative));
Frm.Content = p;
// This will print 0
int i = VisualTreeHelper.GetChildrenCount(p);
System.Diagnostics.Debug.WriteLine("Children count = " + i);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
// Now it will correctly print 1, as 'p' is now part of VisualTree
int i = VisualTreeHelper.GetChildrenCount(p);
System.Diagnostics.Debug.WriteLine("Children count = " + i);
}
另一个例子:
function before(){
// declare variables
function x(){
}
// do stuff
return x();
}
function after(){
// declare variables
// do stuff
return y();
// ------------------------
function y(){
}
}
答案 0 :(得分:2)
这是个人选择的问题,两者都有甜蜜的一面。
在后一种情况下,当开发人员需要快速阅读如何在源文件的顶部调用函数时,它非常有用,而无需向下滚动并阅读有关函数实现的详细信息。
当以角度js绑定成员时,遵循接近第二个的样式。 Here是关于角度js如何将成员绑定到顶部
的推荐样式指南的链接答案 1 :(得分:0)
由于功能在范围内被提升,因此没有真正的区别,只有偏好 返回的自然位置在最后,为什么不在那里呢?