ractivejs / ractivejs.github.io

https://ractive.js.org
8 stars 33 forks source link

fix bug in https://ractive.js.org/tutorials/hello-world/ step 1, code line 33 #154

Open sfthurber opened 6 years ago

sfthurber commented 6 years ago

bug: var ractive = Ractive({ fix: var ractive = new Ractive({

fskreuz commented 6 years ago

Hi! Thanks for the PR (your very first one to be precise 🎉 ). Unfortunately, it's not a bug. Ractive can be called with or without new. Under the hood, Ractive has a "constructor guard" which creates a new instance with new if the constructor was invoked as a regular function.

See https://github.com/ractivejs/ractive/blob/dev/src/Ractive.js#L35

sfthurber commented 6 years ago

well, it didn't work in the tutorial when i pasted the code in.it worked after l i clicked "fix code" which changed the instantiation to an explicit "new". so i viewed that as a bug in the tutorial.

On 6/1/18, Joseph notifications@github.com wrote:

Hi! Thanks for the PR (your very first one to be precise 🎉 ). Unfortunately, it's not a bug. Ractive instances can be instantiated with or without new. Under the hood, Ractive has a "constructor guard" which creates a new instance with new if the constructor was like a regular function.

See https://github.com/ractivejs/ractive/blob/dev/src/Ractive.js#L34

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/ractivejs/ractivejs.github.io/pull/154#issuecomment-393875762

sfthurber commented 6 years ago

i'll re-try it and send so screen captures

On 6/1/18, Steve sfthurber@gmail.com wrote:

well, it didn't work in the tutorial when i pasted the code in.it worked after l i clicked "fix code" which changed the instantiation to an explicit "new". so i viewed that as a bug in the tutorial.

On 6/1/18, Joseph notifications@github.com wrote:

Hi! Thanks for the PR (your very first one to be precise 🎉 ). Unfortunately, it's not a bug. Ractive instances can be instantiated with or without new. Under the hood, Ractive has a "constructor guard" which creates a new instance with new if the constructor was like a regular function.

See https://github.com/ractivejs/ractive/blob/dev/src/Ractive.js#L34

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/ractivejs/ractivejs.github.io/pull/154#issuecomment-393875762

fskreuz commented 6 years ago

Ahh... It might be because the copy-paste code looks like

var ractive = Ractive({
  target: output,
  template: template,
  data: { greeting: 'Hello', name: 'world' }
});

but the Fix Code code looks like:

var ractive = new Ractive({
  target: '#target',
  template: '#template',
  data: { greeting: 'Hello', name: 'world' }
});

Notice the target and template. If this is the case, this would be the bug in the docs.

sfthurber commented 6 years ago

captureafterfixcode capturebeforefixcode

this may help--screen captures attached

On 6/1/18, Joseph notifications@github.com wrote:

Ahh... It might be because the copy-paste code looks like

var ractive = Ractive({
  target: output,
  template: template,
  data: { greeting: 'Hello', name: 'world' }
});

but the Fix Code code looks like:

var ractive = new Ractive({
  target: '#target',
  template: '#template',
  data: { greeting: 'Hello', name: 'world' }
});

Notice the target and template. If this is the case, this would be the bug.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/ractivejs/ractivejs.github.io/pull/154#issuecomment-393882420