GithubHelp home page GithubHelp logo

Comments (4)

eskelter avatar eskelter commented on June 14, 2024

@mathiasbynens did he part :) We can easily do what you ask for ourselves:

install node-glob in your project (e.g. npm i glob --save-dev)

then in your gruntfile.js :

var glob = require('glob');

// ...

template: {
    
    some_target: {
        
        // options: { ... },
        
        get files () {
            
            var result = {};
            
            glob.sync('app/**/*.js.tpl').forEach(function (file) {
                
                this[file.replace(/\.tpl$/, '')] = file;
                
            }, result);
            
            return result;
            
        }
        
    }
    
}

from grunt-template.

mhintzke avatar mhintzke commented on June 14, 2024

Oh interesting I was not aware this was possible. Is there any documentation that says we are allowed to use a function in place of the 'files' object? Thanks for the help though.

from grunt-template.

eskelter avatar eskelter commented on June 14, 2024

This is a getter, not a function per se.

It is implemented as a function, but exposed a regular property value. So as far as grunt is concerned, { get files () { return ['value']; } } is the same as { files: ['value'] }: It sees the file property as an Array in either case.

This getter/setter syntax was popular before Object.defineProperty became all the rage (and the standard :-). The latter does offer much more flexibility, but get/set still looks cleaner when your don't need any fancy feature. Let's not even talk about defineGetter :-P

from grunt-template.

mhintzke avatar mhintzke commented on June 14, 2024

Ah I see, I have used getters and setters in C# before but didn't realize they were actually a legacy construct of JS (rather I thought they were ES6+ features). Guess you learn something everyday :) Thanks

from grunt-template.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.