Flex generator in Javascript