This Question is Answered

2 "helpful" answers available (2 pts)
2 Replies Last post: Apr 26, 2012 4:03 PM by Richard Deeming  
Marko Salinic Newbie 3 posts since
Jan 20, 2012
Currently Being Moderated

Apr 25, 2012 10:18 AM

Code inspection for javascript function

Let's say I have a javascript function like this:

 

function SetActiveOrderPosition(orderId){

     var activeOrder = { };

}

 

How can I write custom pattern to convert this function to:

 

SetActiveOrderPosition = function(orderId){

     var activeOrder = { };

}

 

 

I need this because I am refactoring global functions into object level functions

Andrey Serebryansky JetBrains 2,900 posts since
Jan 12, 2005
Currently Being Moderated
Apr 26, 2012 12:05 PM in response to: Marko Salinic
Re: Code inspection for javascript function

Hello Marco

     I'm afraid ReSharper's Structural Search and Replace doesn't support JavaScript yet. Thank you!

 

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

Richard Deeming Novice 150 posts since
Oct 6, 2010
Currently Being Moderated
Apr 26, 2012 4:03 PM in response to: Marko Salinic
Re: Code inspection for javascript function

You should be able to achieve this with Visual Studio's built-in Find & Replace, using Regular Expressions:

 

  • Find what: function:b+{:i}:b*(
  • Replace with: \1 = function(
  • Find options: Use: Regular Expressions
  • Find options: Look at these file types: *.js

 

There's a reference for the perculiar Regex syntax that Visual Studio uses on MSDN:

http://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.100).aspx

More Like This

  • Retrieving data ...