基于微信小程序的知识共享型互动问答系统的设计与实现外文翻译资料

 2021-12-14 10:12

英语原文共 20 页

Identifying Classes in Legacy JavaScript Code

Authors:Leonardo Humberto Silva

Abstract:JavaScript is the most popular programming language for the Web. Although the language is prototype‐based, developers can emulate class‐based abstractions in JavaScript to master the increasing complexity of their applications. Identifying classes in legacy JavaScript code can support these developers at least in the following activities: (1) program comprehension; (2) migration to the new JavaScript syntax that supports classes; and (3) implementation of supporting tools, including IDEs with class‐based views and reverse engineering tools. In this paper, we propose a strategy to detect class‐based abstractions in the source code of legacy JavaScript systems. We report on a large and in‐depth study to understand how class emulation is employed, using a dataset of 918 JavaScript applications available on GitHub. We found that almost 70% of the JavaScript systems we study make some usage of classes. We also performed a field study with the main developers of 60 popular JavaScript systems to validate our findings. The overall results range from 97% to 100% for precision, from 70% to 89% for recall, and from 82% to 94% for F‐score.

1 INTRODUCTION

JavaScript is the most popular programming language for the Web. The language was initially designed in the mid‐1990s to extend web pages with small executable code. Since then, its popularity and relevance only grew.JavaScript is now the most popular language on GitHub, including newly created repositories. Richards also reported that the language is used by 97 out of the web#39;s 100 most popular sites. Concomitantly with its increasing popularity, the size and complexity of JavaScript software is in steady growth. The language is now used to implement mail clients, office applications, and IDEs, which can reach hundreds of thousands of lines of code.

2 CLASSES IN JAVASCRIPT

In this section, we discuss how classes can be emulated in legacy JavaScript code. We also describe the syntax proposed in ECMAScript 6 to support classes

2.1 Class emulation in legacy JavaScript code

An object in JavaScript is a set of name‐value pairs. Methods and variables are called properties, and their values can be any objects, including immediate values (eg, numbers and boolean) and functions. To implement classes in JavaScript, prior to ECMAScript 6 standard, the most common strategy is to use functions. Particularly, any function can be used as a template for the creation of objects. When a function is used as a class constructor, its this is bound to the new object being constructed. Variables linked to this are used to define properties that emulate attributes and methods. If a property is an inner function, then it represents a method, otherwise, it is an attribute. The operator new and the method Object.create(hellip;) are usually used to instantiate classes.

To illustrate the definition of classes in legacy JavaScript code, we use a simple Circle class. Listing 1 presents the function that defines this class (lines 1‐8), which includes 2 attributes (radius and color) and 2 methods (getArea and setColor). Functions used to define methods can be implemented inside the body of the class constructor, like getArea (lines 4‐6), or outside, like setColor (lines 9‐11). An instance of the class Circle is created with the keyword new (line 13).

Each object in JavaScript has an implicit prototype property that refers to another object. The instance link between an object and its class in mainstream object‐oriented languages is assimilated to the prototype link between an object and its prototype in JavaScript. To evaluate an expression like obj.p, the runtime system starts searching for property p in obj, then in obj.prototype, then in obj.prototype.prototype, and so on until it finds the desired property or the search fails. When an object is created using newC its prototype is set to the prototype of the function C, which by default is defined as pointing to Object(the global base object in JavaScript). Therefore, a chain of prototype links usually ends at Object.

2.2 ECMAScript 6 classes

ECMAScript is the standard definition of JavaScript.5 ECMAScript 68 is the latest version of this standard, which was released in 2015

. Interestingly, a syntactical support to classes is included in this last release. For example, ES6 supports the following class definition:

However, this support to classes does not impact the semantics of the language, which remains prototype‐based. For example, the previous class is equivalent to the following code:

The emulation strategies discussed in the previous section straightforwardly detects this code as a Circle class, with a radius attribute and a getArea method. Therefore, identifying class‐like structures in legacy JavaScript code can, for example, motivate developers to migrate such structures to syntax‐based classes, according to the ES6 standard.

3 DETECTING CLASSES IN LEGACY JAVASCRIPT

In this section, we describe our strategy to statically detect classes in legacy JavaScript source code (Subsection 3.1). Subsection 3.2 describes the tool we implemented for this purpose. We also report limitations of this strategy, mainly because of the dynamic natu

资料编号:[5329]

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。