- /*
- * Dynamically instantiate a class. Additional arguments are
- * passed to the class constructor
- *
- * @param {Function} clazz
- * @returns {Object} The instantiated class instance.
- */
- function instantiate( clazz ) {
- var tempClass,
- inst,
- args;
- tempClass = function(){};
- tempClass.prototype = clazz.prototype;
- inst = new tempClass();
- args = Array.prototype.slice.call( arguments );
- args.shift();
- clazz.apply( inst, args );
- return( inst );
- }
- //该片段来自于http://www.codesnippet.cn/detail/270520133573.html
来源: http://www.codesnippet.cn/detail/270520133573.html