【发布时间】:2015-12-20 13:57:09
【问题描述】:
我想将 var "firstWord" 中保存的值从一种方法传递到另一种方法。
var obj = {
getWords: function () {
var words = [];
$('input').each(function () {
words.push($(this).val());
});
var firstWord = words[0],
secondWord = words[1],
thirdWord = words[2];
},
pushWords: function () {
Array.prototype.insert = function (index, item) {
this.splice(index, 0, item);
};
var fruits = ["Banana", "Orange", "Apple", "Mango"],
randomPosition = (Math.floor(Math.random() * (5 - 2 + 1)) + 1);
fruits.insert(randomPosition, firstWord);
$('body').append(fruits);
}
};
可能我的代码有点错误,但在这种情况下有没有可能这样做?
【问题讨论】:
标签: javascript jquery inheritance