これは、オブジェクトを作成してその中に関数を配置する正しい方法ですか? 私が遭遇するすべての例は、理解しやすく、実際の状況で効果的に使用できるコードを使用しています。だから私はこれを理解しようとしています。
function calc() //creating an empty object named calc
{
}
var calc = new calc(); //creating a new instance of the calc object
calc.arithmetic = function maths (input)
{
var str = input;
var a=str.substr(1,1);
var b=str.substr(2,1);
var c=str.substr(3,1);
if(b == "+")
{
answerNumber = a + c;
}
else if(b == "-")
{
answerNumber = a + c;
}
else if(b == "*")
{
answerNumber = a * c;
}
else if(b == "/")
{
answerNumber = a / c;
}
}
document.getElementById("input").value=answerNumber;
document.write(calc.arithmetic(input)) //calling the method in the context of the object.