我一直在尋找最佳解決方案,但我真的不知道我應該找什麼關鍵字。我需要一點點的我問題的解釋:)那是我的代碼:Javascript object/function accesibility inside another
function fluidEdge(params) {
var fluid = {};
fluid.point = function(config){
fluid.x = config.x;
fluid.y = config.y;
};
fluid.renderShape = function(params){
params = params || {};
var x = params.x || 0;
var y = params.y || 0;
point = new fluid.point({
x: x,
y: y
});
console.log(point.x);
};
return fluid;
}
var test = new fluidEdge({});
test.renderShape({x: 50, y: 100});
我的例子要複雜得多,所以我真的不能重建代碼,我已經儘可能簡化它盡我所能。我想在fluid.renderShape
內訪問fluid.point
函數。我不知道我該怎麼做,我嘗試了幾種方法。
之前,我沒有使用var fluid = {};
和fluid.
,但this.
和一切工作正常。
如果我犯了什麼錯誤,你也可以指出。提前致謝。
你的代碼很混亂。什麼是'var fluid = {};'for? – passion