Function Script:NameofFunction()

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Marc Savignac Marc Savignac 5 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37643
    Profile photo of Marc Savignac
    Marc Savignac
    Participant

    Hi,

    I'm reading Step by Step Windows Powershell 3rd edition. At page 187 this function is written:

    Function Script:ConvertToMeters($feet)
    {
    "$feet feet equals $($feet*.31) meters"
    } # end ConvertToMeters

    What is the purpose of Script: before the name of the function?

    #37646
    Profile photo of Don Jones
    Don Jones
    Keymaster

    It's scoping the function to the script that it's in. It's actually a really unusual practice – I'm not sure I've seen anyone do that. You might ask Ed (the author) why he chose to do that. Overall it's kind of chock-full of less-than-good practices – the name doesn't follow naming conventions, the parameter declaration is the truncated kind, and it's outputting text rather than a value. I'm not sure what the context was within the book, but it's not how I'd normally expect a PowerShell function to be written.

    #37663
    Profile photo of Marc Savignac
    Marc Savignac
    Participant

    Thank you for your reply. I noticed the difference from the other functions and I was curious of what it does.

    P.S Powershell in a month of lunches is a very good book 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.