在Java中,创建对象的标准方法是使用
MyClass name = new MyClass();
Run Code Online (Sandbox Code Playgroud)
我也经常看到这个结构
new MyClass() { /*stuff goes in here*/ };
Run Code Online (Sandbox Code Playgroud)
我已经在网上寻找了一段时间,但是找不到第二种构造样式的作用或它是如何做的很好的解释.
有人可以解释你如何以及为什么要使用第二个结构?
我正在研究简化的垂直视差(类似于http://nikebetterworld.com).
我有一个快速的演示工作 - 代码在技术上有效,但我在每个滚动后对重绘有一个紧张的影响 - 似乎javascript发生得很晚.知道为什么吗?我在剧本中看不到任何真正突出的东西.
var getYPosition = function() {
if (typeof(window.pageYOffset) == 'number') {
return window.pageYOffset;
} else {
return document.documentElement.scrollTop;
}
};
$(document).ready(function(){
var sections = $(".section");
$(window).scroll(function() {
var x = getYPosition(),
y = Math.floor(x / 1600),
z = $(sections[y]).offset();
$(sections[y]).css("background-position", "0 " + (getYPosition() - z.top)/2 + "px");
});
});
Run Code Online (Sandbox Code Playgroud) 环境Mono,PostgreSQL,.Net MVC,Windows
我试着展示将来发生的所有事件.
为了做到这一点,我使用以下SQL:
NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM dinners WHERE EventDate >= " + DateTime.Now, dinnerConn);
Run Code Online (Sandbox Code Playgroud)
现在,如果我从DB中比较DateTime.Now和我的EventDate时间戳,我得到以下内容
(EventDate) 12/18/2010 7:00:00 PM - (DateTime.Now) 10/2/2010 7:59:48 PM
Run Code Online (Sandbox Code Playgroud)
它们看起来很容易与我相提并论,但每当我运行此查询时,我都会得到以下结果:
ERROR: 42601: syntax error at or near "8"
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Npgsql.NpgsqlException: ERROR: 42601: syntax error at or near "8" …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用dotnetopenauth进行用户注册.这很棒,而且工作得很好.
问题是,当我尝试去/ Home /时,我遇到了一个错误:
找到了多个匹配名为"Home"的控制器的类型.如果为此请求提供服务的路由('{controller}/{action}/{id}')未指定名称空间来搜索与请求匹配的控制器,则会发生这种情况.如果是这种情况,请通过调用带有'namespaces'参数的'MapRoute'方法的重载来注册此路由.
对'Home'的请求找到了以下匹配的控制器:OpenIdRelyingPartyMvc.Controllers.HomeController
YourApp.Controllers.HomeController
问题是,我不知道 OpenIdRelyingPartyMvc.Controllers.Homecontroller来自哪里.我在我的应用程序的任何地方都找不到"OpenIdRelyingPartyMvc"的任何实例,保存2个位置,这两个位置都发生在UsersController中:
OpenIdRelyingParty openid = new OpenIdRelyingParty();
Run Code Online (Sandbox Code Playgroud)
我已经尝试删除DLL并重建应用程序 - 没有变化.我无法弄清楚这个其他控制器的位置.
有任何想法吗?
我正在使用$().post和php来改变<textarea>的内容.
脚本正在成功 - firebug清楚地显示textarea标签之间的文本已经改变,我的小警报触发.
但是,用户看不到更改.在Firefox中,根本不会发生变化,而在IE中,textarea最迟会更新10秒.
这是我正在使用的jquery:
$(document).ready(function() {
$('#pv_list li:first').addClass('hilite');
$("input[name='db_entries']:first").attr('checked', 'checked');
$("input[name='db_entries']").click(function () {
$.post("changeEntry.php", {post: $(this).val()}, function(data) {
$("textarea").text(data);alert('done');
});
$('#pv_list li').removeClass('hilite');
$(this).parent().addClass('hilite');
});
});
Run Code Online (Sandbox Code Playgroud)
起初我以为是因为页面没有验证,但它验证了xhtml过渡.
真正烦扰我的是我让它早点工作,无法弄清楚我改变了什么.
我正在利用 Array.sort() 对对象数组进行递归排序,每个对象都可能有子对象。
window.sortByrecent = function (a, b) {
if(a.children && !a.isSorted) {
a.children = a.children.sort(window.sortByrecent);
a.isSorted = true;
}
if(b.children && !b.isSorted) {
b.children = b.children.sort(window.sortByrecent);
b.isSorted = true;
}
// Later post comes first
return moment(b.date).unix() - moment(a.date).unix();
}Run Code Online (Sandbox Code Playgroud)
这是由
this.comments.sort(window.sortByrecent);Run Code Online (Sandbox Code Playgroud)
然而,某些帖子没有排序,我正在努力找出原因。在调试器中逐步执行它,看起来如果 a.children 是一个数组,它实际上从未触发递归回调,这意味着它从不检查该评论的子项,因此从不对其进行排序。
有没有办法强制递归?
- - - - 答案 - - - -
this.comments = window.sortByrecent(this.comments);
window.sortByrecent = function (arr) {
if(!arr.isSorted) {
arr.sort(window.compareByRecentNewFirst);
arr.forEach(function(element, index, array) {
if(array[index].children) {
array[index].children = window.sortByrecent(array[index].children);
}
});
arr.isSorted = …Run Code Online (Sandbox Code Playgroud)javascript ×2
jquery ×2
background ×1
c# ×1
java ×1
mono ×1
object ×1
php ×1
postgresql ×1
recursion ×1
scroll ×1
sorting ×1