在这样的代码行中找到了这个运算符:
var t = Object(this),
len = t.length >>> 0;
Run Code Online (Sandbox Code Playgroud)
这个算子是什么意思?
完整代码如下.它是JS some
方法的代码:
if (!Array.prototype.some) {
Array.prototype.some = function(fun /*, thisp */) {
"use strict";
if (this == null) throw new TypeError();
var t = Object(this),
len = t.length >>> 0;
if (typeof fun != "function") throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t && fun.call(thisp, t[i], i, t))
return true;
} …
Run Code Online (Sandbox Code Playgroud) 我正在检查标准PHP库(SPL).我之前只使用过数组,刚才发现PHP有很多标准类.但手册中没有任何词语是否建议使用它.例如,他们明确建议使用foreach
构造来迭代数组,因为它更快.那图书馆怎么样?如果我需要在一个对象中存储一些数据,我应该为我的情况使用一些具体的SPL类,还是使用标准数组更好?
我收到了这条警告信息:
npm WARN安装无法安装可选依赖项:不支持
当我运行命令时:
$ npm i adaro --save
Run Code Online (Sandbox Code Playgroud)
这个警告意味着什么?什么是可选的依赖?这是认真的吗?我该如何摆脱这种警告?
通过检查Zend Framework,我发现所有setter方法(我已经检查过的方法)都会返回它所在类的实例.它不仅设置了一个值,还返回了它$this
.例如:
/* Zend_Controller_Router */
public function setGlobalParam($name, $value) {
$this->_globalParams[$name] = $value;
return $this;
}
/* Zend_Controller_Request */
public function setBaseUrl($baseUrl = null) {
// ... some code here ...
$this->_baseUrl = rtrim($baseUrl, '/');
return $this;
}
/* Zend_Controller_Action */
public function setFrontController(Zend_Controller_Front $front) {
$this->_frontController = $front;
return $this;
}
Run Code Online (Sandbox Code Playgroud)
等等.每个公共制定者都会回来$this
.并且它不仅适用于setter,还有其他返回的操作方法$this
:
public function addConfig(Zend_Config $config, $section = null) {
// ... some code here ...
return $this;
}
Run Code Online (Sandbox Code Playgroud)
为什么需要这个?回来$this
做什么?它有一些特殊含义吗?
我不明白delete
当我想释放分配的内存时真正做了什么new
.在C++ Premiere一书中写道:
这将删除ps指针指向的内存; 它不会删除指针ps本身.例如,您可以重用ps来指向另一个新分配.你应该总是平衡使用new和使用delete; 否则,您可能会遇到内存泄漏 - 即已分配但无法再使用的内存.如果内存泄漏变得太大,它可能会使程序寻求更多的内存停止.
据我所知,delete
必须删除pinter指向的内存中的值.但事实并非如此.这是我的实验:
int * ipt = new int; // create new pointer-to-int
cout << ipt << endl; // 0x200102a0, so pointer ipt points to address 0x200102a0
cout << *ipt << endl; // 0, so the value at that address for now is 0. Ok, nothing was assigned
*ipt = 1000; // assign a value to that memory address
cout << *pt << endl; …
Run Code Online (Sandbox Code Playgroud) TS 抛出奇怪的错误:
错误:(125, 18) TS2569:类型“字符串”不是数组类型或字符串类型。使用编译器选项“--downlevelIteration”来允许迭代器迭代。
为什么字符串不是字符串?
我想看看 TS 将如何为字符串编译扩展运算符。
我在浏览器控制台中的代码。一个字符串被分解成字符:
> s = 'abcdef';
> r = [...s];
< (6) ["a", "b", "c", "d", "e", "f"]
Run Code Online (Sandbox Code Playgroud)
我在 TS 中的代码:
const s: string = 'abcdef';
const res = [...s]; // <= Error: Type 'string' is not an array type or a string type
console.log(res);
Run Code Online (Sandbox Code Playgroud)
为什么?
TS版本:
"dependencies": {
"typescript": "^3.5.3"
}
Run Code Online (Sandbox Code Playgroud)
更新:
更新:
我的 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"downlevelIteration": false,
"allowJs": …
Run Code Online (Sandbox Code Playgroud) 鉴于我有以下配置文件:
[default]
aws_access_key_id=default_access_key
aws_secret_access_key=default_secret_key
[profile testing]
aws_access_key_id=testing_access_key
aws_secret_access_key=testing_secret_key
region=us-west-2
Run Code Online (Sandbox Code Playgroud)
并且鉴于我的默认配置文件的名称是 foo
我需要输入哪些CLI命令才能获取默认配置文件的名称.就像是:
$ aws describe-default-profile
{
...
"default_profile_name": 'foo'
}
Run Code Online (Sandbox Code Playgroud)
或列出所有配置文件,它也输出默认值:
$ aws list-all-profiles
{
[{
...
profile_name: 'foo',
"is_default": true
}]
}
Run Code Online (Sandbox Code Playgroud)
有一个get-instance-profile
on iam
(docs),但它需要指定配置文件的名称:
$ aws iam get-instance-profile --instance-profile-name ExampleInstanceProfile
Run Code Online (Sandbox Code Playgroud) 当我尝试$ react-native run-android
Android模拟器时,我收到此错误:
:app:compileDebugJavaWithJavac
/home/user/app/android/app/src/main/java/com/package/MainApplication.java:8: error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage
import com.airlabsinc.RNAWSCognitoPackage;
^
1 error
Incremental compilation of 1 classes completed in 0.448 secs.
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug …
Run Code Online (Sandbox Code Playgroud) php ×2
amazon-ec2 ×1
android ×1
arrays ×1
c++ ×1
facebook ×1
iterator ×1
javascript ×1
material-ui ×1
new-operator ×1
node.js ×1
npm ×1
operators ×1
react-native ×1
reactjs ×1
return ×1
spl ×1
typescript ×1