我有一個javascript類person
,我做了Obj它,工作正常。但我需要從person
類訪問功能。Javascript OOP初始化和方法調用問題
當我試圖訪問我得到..not a function error
。
請幫忙!
重要......我需要初始化'person'類,並調用與我的代碼完全相同的方法。怎麼樣??幫幫我!
這裏是我的代碼:
var person = {
setBasic: function(data) {
alert(data.name + ' ' + data.age);
},
this:getPerson = function() {
alert('get me');
},
success: null
};
//lets instantiate.enter code here
var perObj = new person.setBasic({ 'name': 'ikair', 'age': 33, });
// works fine..
//now I need to call a function of person class:
perObj.getPerson();
//not working :(... how to call function with prev code?
我認爲變種人應該是一個功能,而不僅僅是一個對象集。然後你將這些功能添加到它的原型。 – zero298