重构 javascript 部分以使其正常运行的过程或工具 [英] Procedure or tool to refactor section of javascript to function

查看:35
本文介绍了重构 javascript 部分以使其正常运行的过程或工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,我发现自己在使用同一组语句,我想将这些语句转换为函数.是否有方法、步骤、程序或工具可以帮助我/帮助我这样做?

From time to time, I find myself using the same group of statements and I would like to convert these statements into function. Are there ways, steps, procedure, or tools that will help me / aid me to do so?

当我在 VS2008 中使用 C# 进行开发时,我会简单地突出显示一组语句,并告诉 VS 自动将它们转换为方法.

When I develop in VS2008 in C#, I'll simply highlight a group of statements, and tell VS to automatically convert these into a method.

再说一遍,如果没有工具,程序就行了.

Again, if there are no tool, a procedure will do.

更新

无需发布代码.这是基于我开发和重构 JS 代码的经验,我在其中发现了一组重复的代码,但我对更改代码持谨慎态度,因为我可能会破坏代码.

No need to post code. This is base on my experience with developing and refactoring JS code in which I've found a duplicate set of codes, but I was wary from changing the code since I might break the code.

搜索和替换在您想用变量替换一组常用表达式时很有用,例如将 $(this) 替换为 $this.

search and replace is useful when you want to replace a set of common expression with a variable, something like replacing $(this) to $this.

推荐答案

PHPStorm 有一个重构方法"功能(OSX 上的 CMD-ALT-M),它可以做到这一点.

PHPStorm has a 'refactor to method' function (CMD-ALT-M on OSX), which does this.

这篇关于重构 javascript 部分以使其正常运行的过程或工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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