require

Node js 入门指南(1)

孤人 提交于 2020-01-07 21:30:04
目录 Node Js 定义 特点 Node使用方式 Tip: 使用导出文件的注意事项 Node 内置模块 http 模块 fs 模块 path内置模块 url内置模块 express框架 APIDOC Node Js 定义 Node Js 是一个运行在服务器端的JavaScript。基于一个Chrome JavaScipt 运行时建立的一个平台 特点 事件驱动I/O服务端 基于V8引擎 速度快,性能好 node -v 查看node js 版本号 使用common js 规范 Node使用方式 REPL 交互模式 在当前目录的cmd当中输入node 退出交互模式 .exit 或者node 直接打开文件 采用require() 方法引入要使用的模块 采用 module.exports 导出文件 声明全局变量时,使用全局对象 global Tip: 使用导出文件的注意事项 exports 默认指向 module.exports 导出作用只有module.exports才拥有。但是如果exports指向了新对象,那么就没有导出作用 // 第一种 module.exports = { a:a, b:b } //第二种 不推荐使用 module.exports.a=a module.exports.b=b //第三种 exports.a = a exports.b = b

RequireJS and THREE.js Orbit Controls

我只是一个虾纸丫 提交于 2020-01-07 02:35:29
问题 I am using THREEjs r83 in a requirejs build. No matter what I do, the OrbitControl is loading & running before THREEjs initiates so I get the persistant error: Uncaught ReferenceError: THREE is not defined Here is the initial part of my file where you can see THREE is required as a shim for the OrbitControl. I've gone over the code repeatedly & cannot work out a solution. Can anyone help me out? requirejs.config({ paths: { three: 'lib/three' }, shim: { 'three': ["lib/FloatFix"], 'lib

How to let parent module to import a child module of the child module in NodeJS

笑着哭i 提交于 2020-01-07 02:22:30
问题 Module A │ └─ Module B (devDependency in Module A's package.json) │ └─ Module C (dependency in Module B's package.json) Module B is what I am developing. But I know that module C would be called in Module A with require('Module C') . And the error I am having is Cannot find module 'Module C' . My current solution is ugly which is: In index.js of Module B exports.Module_C = require('Module_C) || require(path.resolve(__dirname, 'node_modules/Module_C/index'); In Module A require('Module_B')

How to let parent module to import a child module of the child module in NodeJS

纵然是瞬间 提交于 2020-01-07 02:22:22
问题 Module A │ └─ Module B (devDependency in Module A's package.json) │ └─ Module C (dependency in Module B's package.json) Module B is what I am developing. But I know that module C would be called in Module A with require('Module C') . And the error I am having is Cannot find module 'Module C' . My current solution is ugly which is: In index.js of Module B exports.Module_C = require('Module_C) || require(path.resolve(__dirname, 'node_modules/Module_C/index'); In Module A require('Module_B')

How to include all lib folder?

旧街凉风 提交于 2020-01-06 15:43:24
问题 I want to extend core Array class with simple method: class Array def to_hash result = Hash.new self.each { |a| result[a] = '' } result end end I put array.rb into lib/core_ext and tried to require it in application.rb by config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir["#{config.root}/lib/**/"] But still get undefined method 'to_hash' for ["var1", "var2", "var3"]:Array if tried to use it in model method. Of course I rebooted the server after code changes. 回答1:

PHP use array to require php files

天涯浪子 提交于 2020-01-06 06:35:55
问题 I have saw this answer about require multiple php files, I want to do it use class,like this class Core { function loadClass($files) { $this->files = func_get_args(); foreach($files as $file) { require dirname(__FILE__)."/source/class/$file"; } } } But when I use $load = new Core; $load->loadClass('class_template.php'); it doesn't work, can anyone help me to find the error ? 回答1: You should pass $this->files to foreach . $files is a local variable and a string. $this->files is a instance

What is the difference between Rails.application.config.autoload_paths and standard Ruby require/require_relative?

旧街凉风 提交于 2020-01-06 05:50:33
问题 I see that the following configuration in application.rb: config.autoload_paths += %W(#{config.root}/app/models/custom_pack/base) config.autoload_paths += Dir["#{config.root}/app/models/custom_pack/custom_container/**/"] config.autoload_paths += Dir["#{config.root}/app/models/custom_pack/helpers/**/"] config.autoload_paths += Dir["#{config.root}/app/models/custom_pack/extensions/**/"] is in the autoload_paths: Rails.application.config.autoload_paths.grep /custom/ => ["/Users/dviglione

Breaking up a page and use require in PHP

十年热恋 提交于 2020-01-06 05:15:09
问题 I´m working on a new web page, and the pages gets extremly long with thousands of rows. So I´m planning on breaking up the page´s different sections into several pages and then display them using require_once() or require() in the main page. My question is if this will affect the speed when the pages load? It feels that way since it has to open up and load several pages. But maybe I´m wrong? 回答1: Don't worry about it. The difference is rarely important. require_once() is slower than require()

exception while importing module in ember js

不羁岁月 提交于 2020-01-06 03:30:07
问题 I need to remove diacritics from string in emberjs app. I found a plugin for this: fold-to-ascii but I don't know how to use it in my app. I added this plugin via npm and it is visible under node_modules folder in my app In docs usage of this plugin is: var foldToAscii = require("fold-to-ascii"); foldToAscii.fold("★Lorém ïpsum dölor.") but i get an exception: Uncaught Error: Could not find module fold-to-ascii also tried importing it like @Kori John Roys suggested: import foldToAscii from

react native底部tab栏切换

家住魔仙堡 提交于 2020-01-05 15:02:13
1.安装tab栏插件 npm i react-native-tab-navigator --save 2.引入对应的组件和tab插件 import { Platform, StyleSheet, Text, View,Image } from 'react-native'; import TabNavigator from 'react-native-tab-navigator'; 3.复制以下代码到render()函数的return 里 两个图标的地址: https://raw.githubusercontent.com/knightsj/GitHubPopular-SJ/master/github_client/res/images/ic_polular.pnghttps://raw.githubusercontent.com/knightsj/GitHubPopular-SJ/master/github_client/res/images/ic_trending.png <View style={styles.container}> <TabNavigator> <TabNavigator.Item selected={this.state.selectedTab === 'home'} title="最热" renderIcon={() => <Image style=