从对象方法内部的数组中运行console.log
Running a console.log from an array thats inside a method of an object
我今天刚在学校学习对象,我知道函数可以从对象内部运行,但该函数实际上被称为方法,我的方法有一个数组,我喜欢通过更改全局变量在console.log中获得一个特定的目标。这能做到吗?我在最后一个控制台上得到的都是未定义的。log->ing at"+worker.getLocation.myLocation);所以实际上我正在尝试更改全局变量var myLocation=0,以在getLocation方法中输出不同的myLocation。
var myLocation = 0
var worker = {
realName: "Willson",
title: "Assistant Maintenance Supervisor",
maintenance: true,
vehicals: ["2008 Dodge Caliber SRT-4", "2012 Jeep Wrangler Unlimited" ],
getLocation: function () {
myLocation [0] = "Villas at Sunrise Mountain";
myLocation [1] = "Reno Villas";
myLocation [2] = "lost";
myLocation [3] = "back home";
}
};
console.log(worker.realName + " is a " + worker.title + " and drives a " + worker.vehicals[1] + " to work.");
var destination = {
property: ["Villas at Sunrise Mountain", "Reno Villas", "lost", "back home"]
};
console.log ("He sold his " + worker.vehicals[0] + "." + " Today he is working at " + worker.getLocation.myLocation);
var myLocation = 0
var worker = {
realName: "Willson",
title: "Assistant Maintenance Supervisor",
maintenance: true,
vehicals: ["2008 Dodge Caliber SRT-4", "2012 Jeep Wrangler Unlimited" ],
getLocation: function () {
var myLocationss = [];
myLocationss [0] = "Villas at Sunrise Mountain";
myLocationss [1] = "Reno Villas";
myLocationss [2] = "lost";
myLocationss [3] = "back home";
return myLocations[myLocation];
}
};
console.log(worker.realName + " is a " + worker.title + " and drives a " + worker.vehicals[1] + " to work.");
var destination = {
property: ["Villas at Sunrise Mountain", "Reno Villas", "lost", "back home"]
};
console.log ("He sold his " + worker.vehicals[0] + "." + " Today he is working at " + worker.getLocation());
相关文章:
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- 使用压缩的JavaScript文件(不是运行时压缩)
- Javascript运行php文件,然后下载文件
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- Angularjs代码未在匿名函数中运行
- jquery设置为使用参数运行
- 如何根据时间运行不同的脚本
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- 将文本框链接到由按钮运行的javascript公式
- 谷歌地图:函数返回未定义的值在console.log中运行良好
- console.log无法运行Mac OS X
- 如何使用Karma单元测试运行程序捕获console.error
- 在NodeJS中使用promise时未运行Console.log
- 从对象方法内部的数组中运行console.log
- 为什么 console.log() 一直在这个循环中运行
- 为什么console.log运行无限循环,直到溢出,和文档.不写
- JavaScript console.dir和运行时
- 在console.log中运行一个函数
- 如何使 console.log() 在 Phantomjs 中同步运行