箭头功能是否比v8中的普通独立功能声明更快(更高性能,更轻)? [英] Are arrow functions faster (more performant, lighter) than ordinary standalone function declaration in v8?

查看:86
本文介绍了箭头功能是否比v8中的普通独立功能声明更快(更高性能,更轻)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问这个问题,因为我和我的同事对编码风格存在争议,因为他更喜欢箭头功能声明:

I am asking this question because I and my colleague have a dispute on coding style because he prefers arrows function declaration:

const sum = (a, b) => a + b;

我更喜欢旧式的独立功能声明:

And I prefer old-style standalone function declaration:

function sum(a, b) {
    return a + b;
}

我的观点是旧式代码更易读,你可以更清楚区分函数和变量声明。他的观点是带箭头函数的代码运行得更快。

My point is that code in old-style more readable and you can more clearly distinguish function and variable declarations. His point is that code with arrow functions just run faster.

当你使用旧式独立函数声明而不是使用旧式独立函数声明时,你是否知道有关实际性能损失的内容(在第8节中)箭头功能?这种惩罚真的存在吗?

Do you know something about actual performance penalties (in v8) when you use old-style standalone function declaration instead of arrow functions? Are that penalties really exists?

推荐答案

V8开发人员在这里。箭头函数(大多数)只是常规函数声明的语法糖。它们并不快。

V8 developer here. Arrow functions are (mostly) just "syntactic sugar" for conventional function declarations. They are not faster.

这篇关于箭头功能是否比v8中的普通独立功能声明更快(更高性能,更轻)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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