为什么这...继承与CoffeeScript的
class Person
name: "initial name"
constructor: (@name) ->
class User extends Person
password: "initial password"
f = new User "Felds"
console.log f
console.log "my name is '#{f.name}' and my password is '#{f.password}'"
b = new User "Bob"
b.password = "bob's password"
console.log b
...当通过coffee -p test.coffee | node
输出这个运行?
{ name: 'Felds' }
my name is 'Felds' and my password is 'initial password'
{ name: 'Bob', password: 'bob\'s password' }
为什么不上console.log f
的password
物业展?它在哪里存储,它是如何检索的?
你可以直接写'coffee test.coffee'你不需要做这个疯狂的事。 – david
@david我试图理解生成的代码(因此'-p'),然后有时我坚持'|节点“的前面,以运行代码。无论如何,谢谢你的提示。 ;) –