我正在阅读John Resig的" Pro Javascript Techniques ",我对一个例子感到困惑.这是代码:
// Create a new user object that accepts an object of properties
function User( properties ) {
// Iterate through the properties of the object, and make sure
// that it's properly scoped (as discussed previously)
for ( var i in properties ) { (function(){
// Create a new getter for the property
this[ "get" + i ] = function() {
return properties[i];
};
// Create a new setter for the property
this[ "set" …Run Code Online (Sandbox Code Playgroud) 我已经阅读了一些文章,我理解了以下内容(如果我错了,请纠正我和/或编辑问题):
java堆是这样分段的:
年轻一代:创建的对象在这里,这部分经常和廉价地垃圾收集
老一代:在Young年代的垃圾收集中存活的对象进入这里,这个区域垃圾收集频率较低,并且使用更多CPU要求的过程/算法(我相信它被称为标记扫描)
编辑:如其他用户所述,PermGen不是所谓的区域的一部分 heap
所以,知道这一点......为什么我的PermGen空间会在应用程序负载过重时增长?对于我之前所说的这个空间不应该在应用程序加载的情况下逐渐填充,但正如我在开始时所说的那样,我可能错误地做了一些假设.
事实上,如果PermGen空间正在增长,有没有一种垃圾收集或重置方式?
在这里浏览MDC文档,我注意到有很多版本的javascript(1.6到1.8.5).
我在想:
是否支持Browser/Javascript版本的在线参考?
是否有任何实际应用程序使用不同的JavaScript版本?根据MDC,你需要做这样的事情来使用它们:
<script type="application/javascript;version=1.7"/>
我在任何网站IIRC都没见过.
谢谢!
如何获取使用Slick插入的记录的自动递增值?下面的代码打印1111.我原本预计它会打印1234
import scala.slick.driver.H2Driver.simple._
object TestMappedTable extends App{
case class User(id: Option[Int], first: String, last: String)
object Users extends Table[User]("users") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def first = column[String]("first")
def last = column[String]("last")
def * = id.? ~ first ~ last <> (User, User.unapply _)
}
implicit val session = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver").createSession()
session.withTransaction{
Users.ddl.create
print(Users.insert(User(None, "Jack", "Green" )))
print(Users.insert(User(None, "Joe", "Blue" )))
print(Users.insert(User(None, "John", "Purple" )))
print(Users.insert(User(None, "Jim", "Yellow" )))
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Slick 0.11.2 for Scala 2.10.0-RC1
我想知道为什么这是有效的代码:
func FindUserInfo(id string) (Info, bool) {
it, present := all[id]
return it, present
}
Run Code Online (Sandbox Code Playgroud)
但事实并非如此
func FindUserInfo(id string) (Info, bool) {
return all[id]
}
Run Code Online (Sandbox Code Playgroud)
有没有办法避免临时变量?
我在js做了一些继承,以便更好地理解它,我发现了让我困惑的东西.
我知道当你用new关键字调用'constructor function'时,你得到一个新对象,引用该函数的原型.
我也知道,为了进行原型继承,你必须用你想成为'超类'的对象的实例替换构造函数的原型.
所以我做了这个愚蠢的例子来尝试这些概念:
function Animal(){}
function Dog(){}
Animal.prototype.run = function(){alert("running...")};
Dog.prototype = new Animal();
Dog.prototype.bark = function(){alert("arf!")};
var fido = new Dog();
fido.bark() //ok
fido.run() //ok
console.log(Dog.prototype) // its an 'Object'
console.log(fido.prototype) // UNDEFINED
console.log(fido.constructor.prototype == Dog.prototype) //this is true
function KillerDog(){};
KillerDog.prototype.deathBite = function(){alert("AAARFFF! *bite*")}
fido.prototype = new KillerDog();
console.log(fido.prototype) // no longer UNDEFINED
fido.deathBite(); // but this doesn't work!
Run Code Online (Sandbox Code Playgroud)
(这是在Firebug的控制台中完成的)
1)为什么如果所有新对象都包含对creator函数原型的引用,fido.prototype是未定义的?
2)继承链[obj] - > [constructor] - > [prototype]而不是[obj] - > [prototype]?
3)我们的对象(fido)的"原型"属性是否曾被检查过?如果是这样的话......为什么'deathBite'未定义(在最后一部分)?
鉴于此代码:
class Rational(n: Int, d: Int) {
require(d != 0)
private val g = gcd(n.abs, d.abs)
val numerator = n / g
val denominator = d / g
def this(n: Int) = this(n, 1)
override def toString = numerator + "/" + denominator
def +(r: Rational) = new Rational(numerator * r.denominator + r.numerator * denominator, denominator * r.denominator)
def *(r: Rational) = new Rational(numerator * r.numerator, denominator * r.denominator)
def +(i: Int) = new Rational(i) + this
private def gcd(a: …Run Code Online (Sandbox Code Playgroud) 我最近听说过BDD,发现它与TDD非常相似.
你使用这两个中的哪一个(如果有的话)?
哪个是各自的利弊?
我需要从在Firefox中运行的脚本发出跨域请求(它仅用于开发目的).
这可以实现吗?也许修改about:config键?
谢谢!
我将一些字符串外部化为HOCON application.conf.我正在访问这样的配置值:
import play.api.Play.current
import play.api.Play.configuration
configuration.getString("foo.bar").get()
Run Code Online (Sandbox Code Playgroud)
尽可能早,如果缺少密钥就会快速失败,就像文档说的那样.
现在我的一些依赖于配置对象的测试失败了,堆栈跟踪表明:
Caused by: java.lang.RuntimeException: There is no started application
我假设这与配置有关?我怎样才能解决这个问题?(测试是规格2)
javascript ×4
scala ×2
agile ×1
bdd ×1
browser ×1
cross-domain ×1
firefox ×1
function ×1
go ×1
inheritance ×1
java ×1
memory-leaks ×1
prototype ×1
slick ×1
specs2 ×1
tdd ×1
testing ×1
version ×1