请你解释一下*显然*不一致的行为给我:
use strict;
sub a { 2 + 2 };
print 2 * a(); # this prints: 8
print a() * 2; # this prints: 8
print 2 * a; # this prints: 8
print a * 2; # this prints: 4
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答,非常有帮助 - 我学到了很多东西.
我不是网络开发人员,想要了解传递变量的更好方法.在过去,我使用各种方法将事物传递给java脚本函数.我从未使用过表单,因为我总是将它们与服务器和数据库相关联.我有一个网站,用户选择更改网站的内容.
我想知道你是否可以使用没有任何服务器的表单,只是将一些东西传递给javascript函数,用于更改页面内容.对于基本示例,如果有人选择男性页面背景变为蓝色,如果他们选择女性,则背景变为粉红色.表单是否可以去,只需提交调用javascript函数?我如何实际将表单内容传递给javascript函数?
MS-DOS命令attrib更改单个文件的属性.如何使用它来更改一组文件的属性?
好的,我不知道如何在没有显示的情况下实际问这个问题.(还解释了为什么我无法弄清楚如何在Google上搜索它.)
鉴于代码如下:
dijit.byId('leftNavigationPane').onLoad = function(){setSecondaryNav(url.secondaryNavId);};
我想要对变量url.secondaryNavId进行评估,所以我真正想要的是对它进行如下处理:
dijit.byId('leftNavigationPane').onLoad = function(){ setSecondaryNav('item1'); };
我相信可能有更好的方法来做到这一点,所以请随意提出建议.
如果我这样做 -
alert(anchor);
Run Code Online (Sandbox Code Playgroud)
我明白了 -
"[object HTMLLIElement]"
......好吧,是的,这是我想要的元素.所以我想获得那些元素ID.
所以我测试它是这样的:
alert(anchor.attr("id"));
Run Code Online (Sandbox Code Playgroud)
......但我什么也没有警觉.我不能选择一个元素.我做错了什么,我不明白什么?
如何在我的函数中返回一个一次性对象以确保它在using块内正常工作?在我的函数中,我想对一次性对象进行操作并考虑错误,这使问题变得复杂。
到目前为止,我有类似于以下代码的内容:
DBHandle GetDB()
{
/* // I can't do this, because the using block would dispose of my object within this function
using( var db = DatabaseObj.GetHandle() )
{
db.Open();
return db;
}
*/
var db = DatabaseObj.GetHandle();
try
{
db.Open();
return db;
}
catch (Exception ex)
{
db.Dispose();
throw ex;
}
}
// In other code:
using( var obj = GetDB() ){ /* ... */ }
Run Code Online (Sandbox Code Playgroud)
除了以下问题,不确定问这个问题的最佳方式:
我正在编写一个接受名为'x'的变量的函数.
function doIt(x){
var y = someformula; //this is just a placeholder for the correct formula
return y;
}
Run Code Online (Sandbox Code Playgroud)
这就是我期望的回报:
if (x is between 0 and 9){ y = 0; }
if (x is between 10 and 19){ y = 32; }
if (x is between 20 and 29){ y = 64; }
if (x is between 30 and 39){ y = 96; }
Run Code Online (Sandbox Code Playgroud)
等等....
任何帮助表示赞赏.
如果重要的话,我是用JavaScript做的.
javascript ×4
batch-file ×1
c# ×1
closures ×1
command-line ×1
dos ×1
forms ×1
formula ×1
html ×1
idisposable ×1
jquery ×1
math ×1
perl ×1