JavaScript is required to use Bungie.net

Tema libero

Naviga in una tempesta di discussioni disparate.
Modificato da dazarobbo: 1/29/2013 6:44:42 AM
6

Retrieve function body as string

[quote]Object.defineProperty(Function.prototype, "Source", { get: function(){ return /{([\s\S]+)}/.exec(this.toString())[1]; } });[/quote]Magic. I seem to have posted this in the wrong place...

Lingua:

 

Fate i bravi. Prima di postare date un'occhiata al nostro codice di condotta. Annulla Modifica Crea squadra Invia

Visualizza l'intera discussione
  • Modificato da Avants Garde: 1/29/2013 11:51:08 PM
    I like to use the normal naming convention, starting with lowercase. Also, 'this' works, but I guess for clarity, toString is okay too. I hate floating regexes like that, so I would rather do this altogether: [quote]this.toString().match(/{([\s\S]+)}/)[1];[/quote]

    Lingua:

     

    Fate i bravi. Prima di postare date un'occhiata al nostro codice di condotta. Annulla Modifica Crea squadra Invia

    1 Rispondi
    Non ti è permesso visualizzare questo contenuto.
    ;
    preload icon
    preload icon
    preload icon