[英]Javascript empty function and prototype usage
MathUtils = function() {};
MathUtils.prototype.sum = function(number1, number2) {
return number1 + number2;
}
MathUtils.prototype.substract = function(number1, number2) {
return number1 - number2;
}
The above is a code snippet that I am currently testing using Jasmine.以上是我目前正在使用 Jasmine 测试的代码片段。 Can someone please help me understand what is the significance of Line no 1?
有人可以帮我理解 1 号线的意义吗? The file name is MathUtils.js.
文件名为 MathUtils.js。 Also it would be really helpful if I could get a brief on what.prototype is.
如果我能简要介绍一下 what.prototype 是什么,那也将非常有帮助。
The significance of line 1 is that it creates an Object instance.第 1 行的意义在于它创建了一个 Object 实例。 Prototype is the chain that mimics inheritance in JavaScript.
原型是模仿 JavaScript 中的 inheritance 的链。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.