dongxu1668 2014-07-30 20:48
浏览 19
已采纳

通用函数:JavaScript还是PHP? [关闭]

While working on a recent project, I began wondering when somebody may use JavaScript vs. PHP for a generic function. Take this basic function (in JS) as an example, which simply returns whether or not a number falls within a particular range:

function range(num, var1, var2) {
    if ((num >= var1) && (num <= var2)) {
        return true;
    }

    else {
        return false;
    }
}

For something that doesn't query a database, nor is it information that should be — or needs to be — indexed for SEO (I know by default JavaScript will not be indexed), then my inference would be that JavaScript would be sufficient. But at the same time, PHP could be as well.

Basically, if the ONLY point of the application were a simple function like above (not that I can see a reason for that, but I digress...), then which langauge would be better to write this in? JavaScript or PHP?

Would love any insight as to which would be the best method to use and why. I recognize there is no right or wrong answer necessarily, but would like to hear arguments for or against one over the other.

Thanks!

  • 写回答

1条回答 默认 最新

  • duankanyi6539 2014-07-30 21:00
    关注

    As you point out, there is no necessarily right or wrong answer. I would say that it depends:

    -Is it a problem for people to be able to reverse engineer the code?

    -Is it a problem if it does not execute because JavaScript might be disabled?

    -Is it preferable to have code execute client-side versus server-side from a performance point of view?

    -Does the content generated by the output of this function qualify as something you might want indexed by Search Engines?

    Depending on the importance of the above criteria/questions, JavaScript might be disqualified. From the points above, the common thing seems to be that choosing for JavaScript is more likely to lead to potentially undesirable side-effects.

    The safest bet, from what I theorize, is therefore the server-side language, PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?