需要在Javascript函数中使用gelp吗? [英] Need a gelp in functions in Javascript?

查看:75
本文介绍了需要在Javascript函数中使用gelp吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我想知道

Hi guys I want to know

Calculator.prototype = {
    add: function() {
        this.calculate();
        this.operation = function(a, b) {
            return a + b;
        };
        this.setCurrent(0, "");
        this.fractionExp = 0; // decimal fix
    },





如何在没有原型的情况下编写上面的代码?

我的意思是我可以把它写成:



how to write the above code without prototype?
I mean Can I write it as:

function add() {
        this.calculate();
        this.operation = function(a, b) {
            return a + b;
        };
        this.setCurrent(0, "");
        this.fractionExp = 0; // decimal fix





谢谢....



Thank you....

推荐答案

我可以把它写成

No.



这里有一些东西:

1. 计算器看起来像一个定义的宾语。可能是你可能指的插件。

2. 计算器对象已定义方法,如 calculate() setCurrent()等等

3.你尝试的是没有连接/引用计算器对象

4.如果没有引用,您的代码将尝试查找将丢失的各种方法调用,因此您将收到错误。



因此,截至目前的转换不正确,无效。
Can I write it as
No.

There are few things here:
1. Calculator looks like a defined object. Probably a plugin that you might be referring to.
2. Calculator object has defined methods like calculate(), setCurrent(), etc in it
3. What you try is no where connected/referenced to Calculator object
4. Without reference, your code will try to look for various method calls that will be missing and thus you will get an error.

So, the conversion as of now is incorrect and will not work.


这篇关于需要在Javascript函数中使用gelp吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆