js advanced factory function

1. Factory function: a function that returns an object
2. Advanced factory function: a factory function whose parameters are callback functions and factory functions
3. Examples:

<script>
        function superFunc(factory){
    
    
           return (...arguments)=>{
    
    
            console.log(...arguments)
                const instance=factory(...arguments)
                const time=new Date()
                return {
    
    
                    time,
                    instance
                }
           }
        }
        let createOrder=superFunc(function(ingredients){
    
    
            return {
    
    
                type:"order",
                ingredients
            }
        })
        console.log(createOrder('text'))
    </script>

Guess you like

Origin blog.csdn.net/weixin_44494811/article/details/113126414