我知道这很简单,但我似乎无法找到我的问题的答案。
许多参考文献表明,如果您具有相同的函数名称,则在调用(覆盖)函数时只会调用该函数的最后一个实例。
如果函数是箭头函数,我似乎无法做到这一点。
正常功能行为:
class A {
constructor() {
this.something();
}
something() {
console.log('I am A');
}
}
class B extends A {
something() {
console.log('I am B');
}
}
let b = new B();Run Code Online (Sandbox Code Playgroud)
这确实覆盖了something()函数,class A但something()如果它是箭头函数格式,我似乎无法覆盖函数。
class A {
constructor() {
this.something();
}
something = () => {
console.log('I am A');
}
}
class B extends A {
something = () => {
console.log('I am B');
}
}
let b = new B(); …Run Code Online (Sandbox Code Playgroud)我管理着一些 WordPress/WooCommerce 在线商店,这些商店已经运行了几年没有问题。最近,我们注意到我们通过 Paypal 进行的交易无效。
我尝试使用 PayPal 自己处理订单并收到以下错误:
很抱歉,目前似乎无法正常工作。请稍后再试
WooCommerce 表示这不是他们软件的问题,但很可能是特定 PayPal 帐户的问题。像往常一样,贝宝支持说“贝宝没有问题”
在不拆开 WooCommerce 代码的情况下,我不确定下一步该去哪里......
我正在构建 2 个应用程序;一个前端,一个后端。
后端将使用 Rails API + Doorkeeper Gem(oauth2 提供程序)构建,而前端将使用 React Native 构建。
目前,我正在使用“客户端凭据授予流程”,它目前工作正常。但是经过一段时间的研究,这个流程不应该用于客户端应用程序,因为它会暴露client_secret是否有人反编译应用程序。
我还阅读了“隐式授权流”,它只需要client_id. 但是这个流程现在看起来有点老了?
根据这个:https : //auth0.com/docs/api-auth/which-oauth-flow-to-use#is-the-client-a-single-page-app-
建议使用“带有 PKCE 的授权代码授予”而不是“隐式授予流程”。我能够让它工作,但问题是它仍然需要client_secret为了获得access_token,这是应该的吗?
这是我正在做的示例流程:
curl -X POST 'http://localhost:3000/oauth/authorize?client_id=xxxx&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=public&code_challenge=testchallenge&code_challenge_method=plain'
Run Code Online (Sandbox Code Playgroud)
这会给我以下回复:
{
"status": "redirect",
"redirect_uri": {
"action": "show",
"code": "8quZ-EAiKKG2EKnQiSYs3xeFRCgsIwcTbaWNdjnpyFg"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将使用上面的代码使用以下请求获取访问令牌:
curl -i http://localhost:3000/oauth/token \
-F grant_type="authorization_code" \
-F client_id="xxxx" \
-F client_secret="xxxx" \
-F code="8quZ-EAiKKG2EKnQiSYs3xeFRCgsIwcTbaWNdjnpyFg" \
-F redirect_uri="urn:ietf:wg:oauth:2.0:oob" \
-F code_verifier="testchallenge"
Run Code Online (Sandbox Code Playgroud)
现在问题来了,为了交换code到一个access_token我仍然需要client_secret. 如果两者都只公开我的client_secret. …
重现步骤:
react-native init myproject。cd myproject。npm install jsdom。import jsdom from 'jsdom';.react-native run-ios。预期输出: 应用程序在 React 本机登陆页面上启动。
实际输出:
无法解析模块: Haste 模块映射path中不存在模块/Users/davidangulo/Desktop/mobile/myproject/node_modules/jsdom/lib/api.jspath
根据他们的自述文件:(https://github.com/jsdom/jsdom)
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
Run Code Online (Sandbox Code Playgroud)
这就是初始化它的方式,但不幸的是,它不起作用。
我正在尝试向 jQuery .validate 添加一个方法来检查 Summernote(所见即所得编辑器)文本区域是否为空,并且我无法触发该方法(我放置在其中的警报不显示)。控制台中没有错误。
方法是:
//Add validation method to check for an empty Award Description
$.validator.addMethod("htmlEditorEmpty", function(value, element) {
alert("checking");
return this.optional(element) || value.summernote('isEmpty');
}, "Please enter details");
Run Code Online (Sandbox Code Playgroud)
这是由(这项工作之前和之后的其他验证)调用的:
awardDescription: {
htmlEditorEmpty: true,
maxlength: 1500,
},
Run Code Online (Sandbox Code Playgroud)
检查 HTML:
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="form-group">
<div>
<textarea class="summernote" id="awardDescription" name="awardDescription" rows="3"></textarea>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我已将其放置在submitHandler 中:
if ($('#awardDescription').summernote('isEmpty')) {//using id
alert('contents is empty1');
}
if ($('awardDescription').summernote('isEmpty')) {//using name
alert('contents is empty2');
}
Run Code Online (Sandbox Code Playgroud)
第一个有效(即,仅在为空时显示),而第二个始终显示(即,即使输入值时)。我包含此信息是因为我相信 .validate 使用名称而不是 id。我可能错了。
我有一张contents桌子.
+------------+------+----------+
| content_id | year | has_file |
+------------+------+----------+
| 1 | 2017 | true |
| 2 | 2018 | true |
| 3 | 2016 | true |
| 4 | 2018 | true |
| 5 | 2018 | false |
+------------+------+----------+
Run Code Online (Sandbox Code Playgroud)
然后我有uploads桌子.
+----+------------+------------+
| id | content_id | filename |
+----+------------+------------+
| 1 | 2 | sample.jpg |
+----+------------+------------+
Run Code Online (Sandbox Code Playgroud)
我想根据最近一年获取数据,然后是否有文件.
我可以使用查询来做到这一点SELECT * FROM contents ORDER BY year DESC, has_file DESC …
我计划使用它SecureRandom.hex为我的用户生成 API 密钥。
到目前为止,这是 3 次执行的输出:
Loading development environment (Rails 5.2.1)
2.3.5 :001 > SecureRandom.hex
=> "0369e9b7c6ffa07bd8d0a263f7b4cfa6"
2.3.5 :002 > SecureRandom.hex
=> "1a8a168d7f70676451e3d59353e22693"
2.3.5 :003 > SecureRandom.hex
=> "94cc188e9e5c3abfe587510fa79993ce"
Run Code Online (Sandbox Code Playgroud)
我获得重复结果的机会有多大?
我创建的这个方法真的能避免产生重复的内容吗?
def generate_string
string = SecureRandom.hex
generate_string if Model.where(:key => string).count > 0
string
end
unique_string = generate_string
Run Code Online (Sandbox Code Playgroud)
我正在使用递归,如果字符串已经存储在数据库中,它只会生成另一个字符串。
而且,由于我没有得到重复的字符串,在用完可SecureRandom.hex生成的组合之前我可以生成多少个字符串?
html ×2
javascript ×2
algorithm ×1
combinations ×1
doorkeeper ×1
ecmascript-6 ×1
html-head ×1
jquery ×1
jsdom ×1
meta ×1
mysql ×1
npm ×1
npm-install ×1
oauth ×1
oauth-2.0 ×1
paypal ×1
paypal-ipn ×1
pkce ×1
probability ×1
rails-api ×1
react-native ×1
ruby ×1
sql ×1
summernote ×1
validation ×1
woocommerce ×1
wordpress ×1
xhtml ×1