我有javascript对象(数组)深拷贝的问题.我读了许多处理它的好方法.我也知道jQuery有这个问题的$ .extend API.但我的问题是:我可以只使用JSON stringify和parse方法来解决这个问题吗?
这是我的代码:
function deepCopy(oldValue) {
var newValue
strValue = JSON.stringify(oldValue)
return newValue = JSON.parse(strValue)
}
var a = {
b: 'b',
c: [1,2,4],
d: null
}
copy = deepCopy(a)
console.log(a === copy) // false
console.log(a.c === copy.c) // false
Run Code Online (Sandbox Code Playgroud)
PS:我知道如果没有所有对象都是可序列化的,但我知道的唯一情况是当对象包含一个属性是函数时.还有其他情况吗?
在清洁代码(第3章,每个功能的一个抽象级别)中有一些关于Stepdown Rule(顶级和低级别的高级功能)的内容.
我使用coffeescript时应该怎么做,因为coffeescript中没有函数声明.
例:
seeAMovie = ()->
BuyTheTicket()
watch()
BuyTheTicket = ()->
//some thing
watch = () ->
//some thing
Run Code Online (Sandbox Code Playgroud)
我想这样做.
这是我的代码:
import Tkinter
top = Tkinter.Tk()
top.geometry('600x600')
scale = Tkinter.Scale(top,from_=10,to=40, orient=HORIZONTAL)
scale.pack()
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
NameError: name 'HORIZONTAL' is not defined
我想将比例尺设置为水平,我的参考在这里,但是它不起作用。