1. let objectFactory = function(constr) {
    2. if(typeof constr !== "function") {
    3. throw "first parameter must be function"
    4. }
    5. let newObj = Object.create(constr.prototype)
    6. let arg = [].slice.call(arguments,1)
    7. let ret = constr.apply(newObj,arg)
    8. let isObject = typeof ret === "object" && ret !== null
    9. let isFunction = typeof ret === "function"
    10. if(isObject || isFunction) {
    11. return ret
    12. }
    13. return newObj
    14. }