# STATUS: Untested

NamedFunction = module.exports = (name, fn) ->
	return Function("fn", "return function #{name} () { return fn.apply(this, arguments) }") fn

NamedFunction.isType = (type) ->
	return testKind { type, kind: Function } and type.name.length > 0

#
# Internal
#

{ noop } = require "./FunctionUtils"
{ testType } = require "./TestUtils"
{ testKind } = require "./KindUtils"

Constructor = require "./Constructor"

Constructor.set [
	NamedFunction, ($$) ->
		instance = NamedFunction name, -> _function.apply this, arguments
		_function = $$.initialize instance
		return null if _function is null
		_function = noop unless testType _function, Function
		return instance
]
