2012-01-31 Logs

本文深入探讨了JavaScript中函数的立即执行与作用域、数组的常用操作与扩展方法,包括函数的应用、数组的最小与最大值查找以及数组清空等核心概念。

<script>
window.onload = function(){
function a(){alert(1);}
var fn = {f:a()}//若这样使用,则立即执行该函数
console.log(fn);
}
</script>

以上写法是错误的

正确写法

<script>
window.onload = function(){
function a(){alert(1);}
var fn = {f:a}
console.log(fn);// fn.f();
}
</script>

<script>
window.onload = function(){
function a(){alert(1);}
var Arr = [a];
Arr[0]();
}
</script>


function fn () {
var _this = this;
_this.name = function(){
alert('This is ' + arguments[0] );
}
}
var cat = new fn();
var dog = new fn();
fn.prototype.type = 'biology';
cat.name('cat');
alert(cat.type);
alert(dog.type);


<script type="text/javascript">
window.onload = function(){
Array.prototype.max = function(){
var _this = this;
if(_this.length>0){
var max = null
for(var i=0;i<_this.length;i++){
if(max==null)
max = _this[i];
else if(max<_this[i])
max = _this[i];
}
}
return max;
}
Array.prototype.min = function(){
var _this = this;
if(_this.length>0){
var min = null;
var index = null;
var indexArray = [];
for(var i =0;i<_this.length;i++){
if(min==null){
min = _this[i];
index = i;
indexArray.push(index);
}
else if(min>_this[i]){
min = _this[i];
index = i;
}
else if(min==_this[i]){
indexArray.push(i);
}
}
}
return {index:(indexArray.length==1?index:indexArray),val:min};
}
Array.prototype.clear = function(){
this.length = 0;
}
var Arr = [0,2,3,0,0,5,9];
console.log(Arr.min());
};
</script>


var i = ' b e f o r e ';
String.prototype.trim = function(){
return this.replace(/\s/g, '');
}
console.log(i);
console.log(i.trim());

### 解决 `torchrun` 中 `--logs` 选项歧义错误 当遇到 `torchrun error ambiguous option --logs could match --logs-specs --logs_specs` 错误时,这表明命令行解析器无法确定 `--logs` 参数应该匹配哪个具体参数。为了消除这种歧义,建议直接使用完整的参数名称。 对于 `torchrun` 命令中的日志记录功能,应明确指定为 `--logs-specs` 或者 `--logs_specs` 来代替简写的 `--logs`[^1]。例如: ```bash torchrun --nnodes=1 --nproc_per_node=8 --logs-specs /path/to/logfile your_script.py ``` 或者如果适用的话, ```bash torchrun --nnodes=1 --nproc_per_node=8 --logs_specs /path/to/logfile your_script.py ``` 确保所使用的参数名完全符合官方文档的要求,并且路径 `/path/to/logfile` 是有效的文件路径而不是字符串形式[^2]。 另外,在处理类似的命令行工具时,总是查阅最新的官方文档来获取最准确的参数说明和支持情况。这样可以避免由于版本更新带来的不兼容问题。 #### 处理其他依赖安装问题 针对提到的 Python 包管理方面的问题,如 `ModuleNotFoundError` 和特定包的安装失败,可以通过以下方式解决: - 对于缺少模块的情况(比如 `importlib_metadata`, `greenlet`, `yaml`),先确认这些库确实已经通过 pip 正确安装。 - 如果仍然存在导入错误,则尝试升级对应的软件包到最新稳定版,因为某些旧版本可能存在已知缺陷或与其他组件冲突。 - 使用虚拟环境隔离不同项目的依赖关系,防止全局环境中残留的老版本影响新项目运行。 最后提醒一点关于 TensorBoard 的启动配置:其 `-logdir` 参数后面跟的是实际的日志目录位置而非字面意义上的字符串,因此不应加引号包裹路径。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值