我正在对一个 Web 应用程序进行建模,您可以通过单击某个链接来访问另一个应用程序页面。我决定做这样的事情:
文件C:/Sandbox/common_page.rb:
require_relative "./pageA"
require_relative "./pageB"
require_relative "./pageC"
require_relative "./pageD"
class CommonPage
def pageA
# click_pageA_link
pageA.new
end
def pageB
# click_pageB_link
pageB.new
end
def pageC
# click_pageC_link
pageC.new
end
def pageD
# click_pageD_link
pageD.new
end
# and so on for other pages..
end
Run Code Online (Sandbox Code Playgroud)
文件C:/Sandbox/pageA.rb:
require_relative "./common_page"
class PageA < CommonPage
def pageA
self
end
end
Run Code Online (Sandbox Code Playgroud)
文件C:/Sandbox/pageB.rb:
require_relative "./common_page"
class PageB < CommonPage
def pageB
self
end
end
Run Code Online (Sandbox Code Playgroud)
对于表示其他页面的类,将提供类似的代码。如果我C:/Sandbox/test.rb使用以下代码运行文件:
require_relative …Run Code Online (Sandbox Code Playgroud) 我一直在从 _why 的书中学习 Ruby,我尝试重新创建他的代码,但它不起作用。
我有一个world.rb文件;
puts "Hello World"
Put_the_kabosh_on = "Put the kabosh on"
code_words = {
starmonkeys: "Phil and Pete, thouse prickly chancellors of the New Reich",
catapult: "Chunky go-go",
firebomb: "Heat-Assisted Living",
Nigeria: "Ny and Jerry's Dry Cleaning (with Donuts)",
Put_the_kabosh_on: "Put the cable box on"
}
Run Code Online (Sandbox Code Playgroud)
在我的另一个文件中, pluto.rb ;
require_relative "world"
puts "Hello Pluto"
puts code_words[:starmonkeys]
puts code_words[:catapult]
puts code_words[:firebomb]
puts code_words[:Nigeria]
puts code_words[:Put_the_kabosh_on]
Run Code Online (Sandbox Code Playgroud)
我知道我的require_relative作品,因为如果我在没有哈希部分的情况下运行 pluto.rb (只是 put "Hello World"),Hello World 就会被打印!
假设我有一个字符串中的js文件的内容。此外,假设它具有exports['default'] = function() {...}和/或其他导出的属性或函数。有什么方法可以将该字符串“要求”(将其编译)为对象,以便我可以使用它?(另外,我不想像require()以前那样缓存它。)
我的代码中有这个
var queries = require('./Queries.js');
在 Windows cmd 中启动节点服务器时就可以了。
我在 linux ec2 服务器中克隆了项目,但是当我启动服务器时无法正常工作
错误:找不到模块“./Queries.js”
我想一次需要几个 Lua 模块,类似于 Java ( import java.awt.*) 中的星号标志。这是我在子目录中组织模块的结构:
<myapp>
-- calculations
-- calc1
-- calc2
-- calc3
-- helper
-- help1
-- help2
-- print
--graphprinter
--matrixprinter
Run Code Online (Sandbox Code Playgroud)
我的客户需要一个子路径的每个模块:
local graphprinter = require("myapp.helper.print.graphprinter")
local matrixprinter = require("myapp.helper.print.matrixprinter")
Run Code Online (Sandbox Code Playgroud)
我更喜欢自动多需求,它从模块路径派生本地表名,并且一次需要整个子路径。这可能是格式:require("myapp.helper.print.*"). 应该为子目录的每个模块自动创建本地表名,这样就没有任何区别,因为我会逐个模块地要求它们。
我有一个应用程序,我需要一个可能可用也可能不可用的文件。如果文件不可用,我需要检查另一个文件。第三个选项将是默认值。到目前为止我有这个
const file = require('./locales/${test1}') || require('./locales/${test2}') || require('./locales/default')
Run Code Online (Sandbox Code Playgroud)
但它给我错误说找不到模块。我如何以最佳方式执行此操作?
我确实尝试过https://www.npmjs.com/package/node-require-fallback但它似乎不起作用,尽管我的节点版本没问题
const messages = require('./locales/${test1}') 效果很好,但是
const 消息 = requireIfExists('./locales/${test1}', './locales/${test2}') 失败
我正在学习 PHP OOP,现在我构建了一个基本的计算器。
这是我的代码index.php:
require_once 'Calculator.class.php';
require_once 'Adder.class.php';
require_once 'Substract.class.php';
require_once 'Operator.interface.php';
require_once 'Multiplier.class.php';
require_once 'Devider.class.php';
$c = new Calculator;
$c->setOperation(new Adder);
$c->calculate(10,50); // 60
echo $c->getResult();
Run Code Online (Sandbox Code Playgroud)
这是Calculator类文件:
class Calculator
{
protected $result;
protected $operation;
public function setOperation(OperatorInterface $operation)
{
$this->operation = $operation;
// var_dump($operation);
}
public function calculate()
{
foreach(func_get_args() as $number)
{
$this->result = $this->operation->run($number,$this->result);
}
}
public function getResult()
{
return $this->result;
}
}
Run Code Online (Sandbox Code Playgroud)
这是在这个类文件中调用的接口:
interface OperatorInterface
{
public function run($number,$result);
}
Run Code Online (Sandbox Code Playgroud)
这是 …
我(成功地)做了一个
npm install --save crypto-js
Run Code Online (Sandbox Code Playgroud)
在当前项目中。它出现在package.json:
$grep crypto package.json
"crypto-js": "^4.0.0",
Run Code Online (Sandbox Code Playgroud)
然后在本地项目 javascript 文件中,我试图使用它但还没有弄清楚。已经尝试了以下方法:
var CryptoJS = require("crypto-js");
Run Code Online (Sandbox Code Playgroud)
import下载aes.js到同一本地目录后,我也尝试使用该方法:
<script type="text/javascript" src="aes.js"></script>
Run Code Online (Sandbox Code Playgroud)
这导致:
未捕获的 ReferenceError:在 my-project-worker.js:1 中未定义要求
Uncaught ReferenceError: CryptoJS is not defined
at encrypt (audio-clips-worker.js:168)
at audio-clips-worker.js:235
at Set.forEach (<anonymous>)
at onmessage (audio-clips-worker.js:229)
Run Code Online (Sandbox Code Playgroud)
最后我尝试留下一个绝对网址:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
Run Code Online (Sandbox Code Playgroud)
这给出了相同的“CryptoJS 未定义”错误。这里有哪些工作选项 - 哪些步骤缺失或需要以不同方式完成?
我在使用 dotenv 时遇到此错误:
(async () => {
^
TypeError: require(...).config(...) is not a function
Run Code Online (Sandbox Code Playgroud)
Evertyghing 工作正常,直到我需要 dotenv。
这是代码
const puppeteer = require('puppeteer');
const fs = require('fs');
require('dotenv').config()
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--start-maximized'],
defaultViewport: null,
});
const page = await browser.newPage();
...more code here
})()
Run Code Online (Sandbox Code Playgroud)
Dotenv 已正确安装:
"dependencies": {
"dotenv": "^8.2.0",
"puppeteer": "^5.3.1"
}
Run Code Online (Sandbox Code Playgroud) 我试图解决我在我的 package.json 中尝试更新 jest 时遇到的问题
开玩笑 26.6.3 ? 27.0.1
我收到错误
TypeError: require(...).createTransformer is not a function
at Object.<anonymous> (/local/repo/elukchm/monorepo/packages/edf/jestPreprocess.js:34:40)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
Run Code Online (Sandbox Code Playgroud)
文件中提到的代码:
jestPreprocess.js
const babelOptions = {
...
};
module.exports = require("babel-jest").createTransformer(babelOptions);
Run Code Online (Sandbox Code Playgroud)
在“babel-jest”里面
const createTransformer = userOptions => {
var _inputOptions$plugins, _inputOptions$presets;
const inputOptions =
userOptions !== null && userOptions !== void 0 ? userOptions : {};
const options = {
...
};
Run Code Online (Sandbox Code Playgroud)
你能看一下并告诉我应该改变什么吗?先感谢您。