我和一些朋友决定开始研究一个项目,我们遇到了Laravel并认为它可能是一个很好的工具.我们开始在本地使用它来开发我们的一些页面并注意到一些奇怪的东西.
当我们使用不同的信息更新视图时,在视图信息发生变化之前大约需要5到10分钟.这就像Laravel正在缓存视图并在其上放置一个TTL.
我知道这不是我在本地Web服务器上做的任何事情,因为我使用过其他框架而且我从未遇到过这个问题.
在搜索互联网时,我找不到如何禁用它的好答案.我想使用Laravel,但是如果每次想要进行更改时我的视图需要一段时间才能更新,那么它会变得毫无价值.事实上,这听起来适得其反.
有没有办法禁用它?为什么我的观点需要永远更新,开箱即用?
有时我看到用参数编写的JavaScript,只要已经有一个设置值或者是一个带方法的对象.以这个jQuery示例为例:
$(".selector").children().each(function(i) {
console.log(i);
});
Run Code Online (Sandbox Code Playgroud)
记录时i,i在查看jQuery each方法中的选择器子项时,您将获得该迭代中的任何值.
拿这个Node.js例子:
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
Run Code Online (Sandbox Code Playgroud)
您可以在此处看到request并且response正在传递它们并且它们包含可以对其执行操作的方法.
对我来说,这看起来像是将函数传递给函数,createServer其中两个参数已经附加了方法.
我的问题是多部分:
我正在浏览jQuery源代码中的一些东西,特别是inArray方法,我找到了这行代码:
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
Run Code Online (Sandbox Code Playgroud)
我所看到的是两个三元运算符,但我不知道如何使用它.我理解三元运算符是如何工作的,但我以前从未见过它像这样使用过.这段代码如何工作?
我最近一直在加强我的PHP游戏.来自JavaScript,我发现对象模型有点简单易懂.
我遇到了一些我想要澄清的怪癖,我似乎无法在文档中找到.
在PHP中定义类时,您可以定义如下属性:
class myClass {
public $myProp = "myProp";
static $anotherProp = "anotherProp";
}
Run Code Online (Sandbox Code Playgroud)
使用公共变量,$myProp我们可以使用(假设myClass在被调用的变量中引用$myClass)$myClass->myProp而不使用美元符号来访问它.
我们只能使用访问静态变量::.因此,我们可以像$myClass::$anotherProp使用美元符号一样访问静态变量.
问题是,为什么我们必须使用美元符号::而不是->?
编辑
这是我认为可以工作的代码(并且确实):
class SethensClass {
static public $SethensProp = "This is my prop!";
}
$myClass = new SethensClass;
echo $myClass::$SethensProp;
Run Code Online (Sandbox Code Playgroud) 这个问题与使用"Object.create"而不是"new"不重复.有问题的线程并不专注于在使用时正确传递参数Object.create
我很好奇我将如何使用Object.create而不是初始化对象new.到目前为止,这是我的代码:
function Human(eyes) {
this.eyes = eyes || false;
}
Human.prototype.hasEyes = function() {
return this.eyes;
}
function Male(name) {
this.name = name || "No name";
}
Male.prototype = new Human(true); //passing true to the Human constructor
var Sethen = new Male("Sethen");
console.log(Sethen.hasEyes());
Run Code Online (Sandbox Code Playgroud)
如上所示,Male.prototype = new Human(true);使用true创建一个新对象.hasEyes()运行该函数时,会按预期记录true.
所以,我的问题是..使用Object.create我将如何以同样的方式传递true参数?
好像我终于理解了JavaScript继承以及如何正确地完成它.这是我的代码:
function Human(eyes) {
this.eyes = eyes ? "Not blind" : "Blind";
}
Human.prototype.canSee = function () {
return this.eyes;
};
function Male(name, eyes) {
Human.call(this, eyes);
this.name = name;
}
Male.prototype = Object.create(Human.prototype);
var Sethen = new Male("Sethen", true);
console.log(Sethen.canSee()); //logs "Not blind"
Run Code Online (Sandbox Code Playgroud)
据我所知,使用Object.create创建继承的原型对象比使用new关键字要好得多.这引起了我脑子里的几个问题.
Male.prototype = Object.create(Human.prototype)将原型链Male.prototype --> Human.prototype --> Object.prototype --> null?Male我Human.call(this, eyes);用来调用超类的构造函数中,我必须在Male构造函数中再次传递眼睛以将其传递给Human构造函数.这似乎很痛苦,有没有更简单的方法呢?Male.prototype = new Human();...这似乎是不正确的.当我们这样做时,实际发生了什么?当我遇到一些奇怪的东西时,我正在玩JavaScript中的一些数组.这是我的代码:
var origArray = new Array("one","two","three","four","five","six","seven","eight");
var newArray = origArray.slice(1,3);
origArray[1] = "octopus";
console.log(newArray.join()); //prints two,three
var origArray = new Array(["one","two"],["three","four"],["five","six"],["seven","eight"]);
var newArray = origArray.slice(1,3);
origArray[1][0] = "octopus";
console.log(newArray.join()); //prints octopus,four,five,six
Run Code Online (Sandbox Code Playgroud)
我不明白为什么newArray在第二种情况下受影响而不是第一种情况.这里发生了什么?
我目前正在阅读Addy Osmani的JavaScript设计模式,可以在这里找到:http://addyosmani.com/resources/essentialjsdesignpatterns/book/.
我发现它非常有趣,非常有帮助.我确实对本书中的一种模式有一个疑问,即命令模式.
在本书中,Addy解释了命令模式有助于更好地解耦对象和方法调用.
这是他的例子我的版本:
var person = {
sayName: function (name) {
return "My name is " + name;
},
sayAge: function (age) {
return "My age is " + age;
},
sayGender: function (gender) {
return "My gender is " + gender;
}
}
person.execute = function (name) {
return person[name] && person[name].apply(person, [].slice.call(arguments, 1));
}
console.log(person.execute("sayName", "Sethen"));
Run Code Online (Sandbox Code Playgroud)
魔术是在execute方法中完成的.如您所见,您传递方法名称和参数,该方法负责其余部分.
我的困惑源于该execute方法实际返回的内容.当你看它时,它看起来像一个短路&&,我一直认为由于JavaScript转换而返回一个布尔值.
但是,如果您尝试使用代码,则可以正常运行,并进行日志记录My name is Sethen.
此外,我发现简单地使用return person[name].apply(person, [].slice.call(arguments, …
我确信这很简单,但我似乎无法让这个工作得恰到好处.这是我的代码:
var zero = 10;
function some(elem, num) {
return elem += num;
}
console.log(some(zero, 10));
console.log(some(zero, 10));
console.log(some(zero, 10));
Run Code Online (Sandbox Code Playgroud)
根据我的理解,我期待变量zero每次增加10 ..所以,它将是10,20和30.相反,我一直得到10.显然,这是不对的.
我的问题是,我zero每次如何将变量增加10并将该值保存回变量zero?
观看道格拉斯·克罗克福德关于高级JavaScript的讲座,他提出了寄生继承的想法,这本质上是构造函数调用其他构造函数来修改有问题的对象.这是他的代码:
function gizmo(id, secret) {
secret = secret || {};
secret.id = id;
return {
toString: function () {
return "gizmo " + secret.id;
}
};
}
function hoozit(id) {
var secret = {},
that = gizmo(id, secret);
that.test = function (testid) {
return testid === secret.id;
};
return that;
}
var myHoozit = hoozit(20);
console.log(myHoozit.test(20)); //returns true
Run Code Online (Sandbox Code Playgroud)
我理解代码,这里没有什么难以理解的.混乱发生在hoozit函数中.如果你没有设置,secret = {}你就不会得到一个true被退回的.
这是令人困惑的,因为在gizmo函数中,你会看到secret = secret || {}哪个应该为我们处理这个......但事实并非如此.
为什么不能正常工作的是短路(secret = secret …