feat: replace new keyword with this constructor syntax and ClassName.new() calls across core library and docs

Replace all uses of the `new` reserved word with explicit `this new()` constructor definitions and `ClassName.new()` instantiation calls in builtin/core.wren. Update all documentation files (classes.markdown, fiber.markdown, fn.markdown, sequence.markdown, error-handling.markdown, expressions.markdown, fibers.markdown, functions.markdown) to reflect the new constructor syntax, removing `new` keyword examples and replacing them with `ClassName.new()` patterns and `this new()` definitions.
This commit is contained in:
Bob Nystrom
2015-07-10 16:18:22 +00:00
parent 121d39cb42
commit e19ff59cce
221 changed files with 864 additions and 654 deletions
+4 -4
View File
@@ -1,16 +1,16 @@
class Foo {
new { _field = "Foo field" }
this new() { _field = "Foo field" }
closeOverGet {
return new Fn { _field }
return Fn.new { _field }
}
closeOverSet {
return new Fn { _field = "new value" }
return Fn.new { _field = "new value" }
}
}
var foo = new Foo
var foo = Foo.new()
IO.print(foo.closeOverGet.call()) // expect: Foo field
foo.closeOverSet.call()
IO.print(foo.closeOverGet.call()) // expect: new value
+1 -1
View File
@@ -2,4 +2,4 @@ class Foo {
write { IO.print(_field) }
}
(new Foo).write // expect: null
Foo.new().write // expect: null
@@ -1,5 +1,5 @@
class Foo {
static bar {
new Fn { _field = "wat" } // expect error
Fn.new { _field = "wat" } // expect error
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ class Foo {
}
}
var foo = new Foo
var foo = Foo.new()
foo.set(1, 2, 3, 4, 5)
foo.write
// expect: 1
+2 -2
View File
@@ -10,9 +10,9 @@ class Outer {
}
}
(new Inner).method
Inner.new().method
IO.print(_field) // expect: outer
}
}
(new Outer).method
Outer.new().method
+9 -13
View File
@@ -1,36 +1,32 @@
// This test exists mainly to make sure the GC traces instance fields.
class Node {
set(left, value, right) {
this new(left, value, right) {
_left = left
_value = value
_right = right
}
write {
write() {
if (_left is Node) {
_left.write
_left.write()
}
IO.print(_value)
if (_right is Node) {
_right.write
_right.write()
}
}
}
var a = new Node
a.set(null, "a", null)
var b = new Node
b.set(null, "b", null)
var c = new Node
c.set(a, "c", b)
var a = Node.new(null, "a", null)
var b = Node.new(null, "b", null)
var c = Node.new(a, "c", b)
a = null
b = null
var d = new Node
d.set(c, "d", null)
var d = Node.new(c, "d", null)
c = null
d.write
d.write()
// expect: a
// expect: c
// expect: b
+1 -1
View File
@@ -3,7 +3,7 @@ class Foo {
init { _field = "value" } // ...before an assignment to it.
}
var foo = new Foo
var foo = Foo.new()
// But invoke them in the right order.
foo.init
foo.write // expect: value