在开发这个小用户时我遇到了一个问题.当我想XMLHttpRequest用我的脚本阻止正在运行的网站中的每一个时,没有发生任何事情(至少在Chrome上):
function main() {
// Override XHR.open with a custom function
window.XMLHttpRequest.prototype.open = function() {
// Nothing... so it's supposed to block every xhr.open() call
}
}
main();
Run Code Online (Sandbox Code Playgroud)
更换时同样的事情window的unsafeWindow.
然而,当我使用这个小技巧时,一切都像魅力一样:
// No more call to main(), and:
var script = document.createElement("script");
script.textContent = "(" + main.toString() + ")();";
document.body.appendChild(script);
Run Code Online (Sandbox Code Playgroud)
每次调用xhr.open都被我的自定义函数替换,不再需要AJAX.
所以我猜这个window元素在main从脚本内部调用时与从<script></script>容器中调用时的元素不同.有人能解释一下为什么吗?
是否有可能在生产中捕获自动布局约束模糊 - 相当于UIViewAlertForUnsatisfiableConstraints断点,但对于生产应用程序?
我的目标是添加一个全局处理程序,将此类错误报告给日志记录系统.
我需要一个父类来访问它的子属性:
class Parent {
private $_fields = null;
public function do_something() {
// Access $_fields and $child_var here
}
}
class Child extends Parent {
private $child_var = 'hello';
}
$child = new Child();
$child->do_something();
Run Code Online (Sandbox Code Playgroud)
当$_fields从子范围修改,它仍然是null在父范围.当尝试使用父范围访问$ child_var时$this->child_var,它当然是未定义的.
我没有找到任何类似"函数集"的内容,只会在子类中复制...
我想要一个函数来返回一个数组的引用:
var a = [1, 2]
var b = [3, 4]
func arrayToPick(i:Int) -> [Int] {
return i == 0 ? a : b
}
inout var d = arrayToPick(0)
d[0] = 6
println(a[0]) // 1
println(d[0]) // 6
Run Code Online (Sandbox Code Playgroud)
我无法返回&a或&b进入,arrayToPick因为那些无法投入[Int].
如何返回的参考a或b从一个函数?
我讨厌块.它们旨在使代码更简洁,但我找不到更丑陋的东西.例如,使用AFNetworking:
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
requestsuccess:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
// Some
// very
// long
// (and as ugly as blocks)
// processing
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON )) {
// Failure code
}]
Run Code Online (Sandbox Code Playgroud)
这样的事情会好得多:
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
requestsuccess:@selector(requestSuccess:response:json:)
failure:@selector(requestSuccess:response:error:)]
Run Code Online (Sandbox Code Playgroud)
那么,是否可以使用方法的选择器作为块?如果没有,我怎样才能使代码更好?
这让我感到很恼火,因为这些块似乎是Objective-c编程的未来,它们只是不可读.
在模板中,我使用以下代码:
{% load i18n %}
{% include "header.html" %}
{% include "top_bar.html" %}
Run Code Online (Sandbox Code Playgroud)
但是,这会产生几个回车(\n),因为我每次分开include,并load用回车.我不想连接像这样的包含:
{% include "header.html" %}{% include "top_bar.html" %}
Run Code Online (Sandbox Code Playgroud)
因为它不可读.
有没有办法避免这些生成的新行?
我正在开发一个使用javascript特定样式指南的项目.例如,if/else语句看起来像这样:
if( condition ){
// Bla bla
}
else {
// Another bla bla
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是一个工具,可以让我根据特定的样式指南检查文件的语法.JSHint/JSLint的不注重款式,封短绒不是定制的,Uncrustify重新格式化文件,而不会警告(和官方不支持Javascript).
我可以通过这个程序获得的最佳输出是来自Closure Linter但具有自定义规则的输出.这个类似问题的答案都是错的.
这样的工具存在吗?
我跑的时候
$ git grep -P "<pattern>"
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
fatal: cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE
Run Code Online (Sandbox Code Playgroud)
如何正确安装GIT并支持OSX的PCRE?
是否可以在不修改代码的情况下监听实例的方法执行或类的所有实例?就像是:
someInstance.addMethodExecutionListener('methodName', handler);
SomeClass.addMethodExecutionListener('methodName', handler);
Run Code Online (Sandbox Code Playgroud)
它将用于记录目的......
从浏览器打印页面时,它引用print.css声明的样式表media="print".浏览器禁用一些CSS规则像background-image和background-color,一些浏览器选项来启用它们.
正如在这个答案中所说,不可能从页面代码中覆盖此行为.
我有两个问题:
javascript ×3
oop ×2
swift ×2
afnetworking ×1
arrays ×1
autolayout ×1
browser ×1
coding-style ×1
css ×1
django ×1
git ×1
greasemonkey ×1
homebrew ×1
ios ×1
java ×1
jshint ×1
jslint ×1
macos ×1
objective-c ×1
parameters ×1
pcre ×1
php ×1
printing ×1
scope ×1
userscripts ×1