我试图从那天开始时获得当前的毫秒数.所以我想做以下计算.86400000-currMilliSecondsFromBeginningOfDay.任何帮助将不胜感激.谢谢
在函数之间传递一个大字符串或对象(比如从ajax响应中)被认为是一种不好的做法吗?以任何方式保存变量中的响应并继续重用该变量是否有益?
所以在代码中它将是这样的:
var response;
$.post(url, function(resp){
response = resp;
})
function doSomething() {
// do something with the response here
}
Run Code Online (Sandbox Code Playgroud)
VS
$.post(url, function(resp){
doSomething(resp);
})
function doSomething(resp) {
// do something with the resp here
}
Run Code Online (Sandbox Code Playgroud)
假设resp是一个大对象或字符串,它可以在多个函数之间传递.
什么是使用之间的区别stop()与clearQueue参数设置为true,只是使用的clearqueue(),如果没有什么区别,为什么两者兼而有之?
假设我在一个脚本中有300个函数.访问每个函数中的arguments对象而不是传入命名参数是不是很糟糕?
编辑:好的,你们很多人都在问我为什么要这样做,这真的是一个理论问题,但是既然你问我有什么理由为什么我想这样做,除了可变参数?
我的问题是关于维护其父对象的原型链的子对象.
在John Resig的高级Javascript幻灯片(http://ejohn.org/apps/learn/#76)中,他写道,为了维护子对象的原型链,您必须实例化一个新的父对象.
然而,通过几个快速测试,我注意到通过将子对象原型设置为等于父对象原型来维护原型链.
任何澄清将不胜感激!
原始代码
function Person(){}
Person.prototype.dance = function(){};
function Ninja(){}
// Achieve similar, but non-inheritable, results
Ninja.prototype = Person.prototype;
Ninja.prototype = { dance: Person.prototype.dance };
assert( (new Ninja()) instanceof Person, "Will fail with bad prototype chain." );
// Only this maintains the prototype chain
Ninja.prototype = new Person();
var ninja = new Ninja();
assert( ninja instanceof Ninja, "ninja receives functionality from the Ninja prototype" );
assert( ninja instanceof Person, "... and the Person prototype" ); …Run Code Online (Sandbox Code Playgroud) 我在这里要做的是创建一个功能,为自定义选择元素执行所有功能.所以我创建了一个函数,它接受函数本身定义的三个参数(更多细节见下面的代码).我正在尝试完成以下操作:我希望参数是各种元素的ID(例如包装器div),我希望在函数中删除这些参数.我的代码如下.非常感谢
function createList(ParentDivID,SelectMenuID,ListMenuID) {
$('#' + ParentDivID + "'");
$('#' + SelectMenuID + "'");
$('#' + ListMenuID + "'");
var options = $("#" + SelectMenuID +'"' ).find("option");
$(options).each(function(){
$(ul).append('<li>' +
$(this).text() + '<span class="value">' +
$(this).val() + '</span></li>');
});
var ul = '<ul id="' + ListMenuID + "></ul>";
$('#' + ParentDivID + "'").append(ul).end().children('#' + ListMenuID + "'").hide().click(function(){$(ul).slideToggle();});
$("#" + SelectMenuID + '"').hide();
}
createList(fancySelectLarge,selectWalkerType,walkerTypeLi);
Run Code Online (Sandbox Code Playgroud)