- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
function main() {
let user = {
firstName: "John",
sayHi() {
print(`Hello, ${this.firstName}!`);
},
};
user.sayHi();
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
function main() {
let user = {
firstName: "John",
sayHi() {
print(`Hello, ${this.firstName}!`);
},
};
user.sayHi();
print("done.");
}
как тебе такое Илон Маск?
+1
function main() {
let { aa, bb } = { aa: 10, bb: 20 };
print(aa + bb);
let {
aa,
bb: { q, r },
} = { aa: 10, bb: { q: 1, r: 2 } };
assert(aa == 10, "{}");
assert(q == 1, "{}");
assert(r == 2, "{}");
let { x, y } = new ObjF(1, "foo");
assert(x == 1, "{}");
assert(y == "foo", "{}");
print("done.");
}
Добрый вечер дорогие неопределившиеся... или заблудшие... вот я тут вам новую фичу притарабанил .. называет деконстракт :)
0
namespace Ifaces {
interface IFoo {
foo(): number;
bar(x: number): string;
twoArg(x: number, y: number): number;
baz: string;
}
class A implements IFoo {
constructor() {
this.baz = "Q" + "A";
}
foo(): number {
return 12;
}
bar(v: number) {
return v.toString();
}
twoArg(x: number, y: number) {
return x;
}
baz: string;
}
class B extends A {
foo(): number {
return 13;
}
}
function foo(f: IFoo) {
return "" + f.foo() + f.baz + f.bar(42);
}
export function run() {
print("Ifaces.run");
let a = new A();
assert("" + foo(a) + "X" == "12.QA42.X");
assert((a as IFoo).twoArg(1, 2) == 1, "t");
a = new B();
assert("" + foo(a) + "X" == "13.QA42.X", "b");
let q = a as IFoo;
q.baz = "Z";
assert("" + foo(q) + "X" == "13.Z42.X", "x");
print("Ifaces.runDONE");
}
}
function main() {
Ifaces.run();
print("done.");
}
хотел оставить вас в покое. но не смог. Ловите - fields в интерфейсах
0
namespace InstanceOf {
class Foo {
x: number
y: string
bar() {
return this.x
}
}
class Bar extends Foo { }
class Baz extends Foo { }
class Bar2 extends Bar { }
class Bar3 extends Bar { }
export function run() {
print("InstanceOf")
assert(new Bar2() instanceof Foo, "if")
assert(new Bar2() instanceof Bar, "ib")
assert(new Bar2() instanceof Bar2, "ib2")
assert(new Bar3() instanceof Bar, "ib")
assert(!(new Bar2() instanceof Baz), "!ib")
assert(!(new Foo() instanceof Baz), "!ib2")
assert(!(new Foo() instanceof Bar), "!ib2")
(new Foo()).bar();
(new Bar3()).bar();
}
}
function main()
{
InstanceOf.run()
print("done");
}
Возрадуйтесь братья и сестры. я вам принес зачатки RTTI :) и узрите этот дампик во очию.
+1
namespace Ifaces {
interface IFoo {
foo(): number;
}
}
class Cls1 implements Ifaces.IFoo
{
foo(): number
{
print("Hello");
return 1;
}
}
function main()
{
const cls1 = new Cls1();
cls1.foo();
const ifoo: Ifaces.IFoo = cls1;
ifoo.foo();
}
Алилуя. я вам интерфейсы принес... узрите теперь дампик
0
let glb1 = 0;
function doubleIt(f: (x: number) => number) {
return f(1) - f(2);
}
function testLambdas() {
let x = doubleIt(k => k * 108);
assert(x == -108, "l0");
}
function main() {
testLambdas();
print("done.");
}
я вам еще принес новых фич.
0
class XFoo {
pin: number;
buf: number[];
constructor(k: number, l: number) {
this.pin = k - l;
}
setPin(p: number) {
this.pin = p;
}
getPin() {
return this.pin;
}
init() {
this.buf = [1, 2];
}
toString() {
return `Foo${this.getPin()}`;
}
}
function main() {
let f = new XFoo(44, 2);
let s = "" + f;
print(s);
}
я вам тут хрень принес.. новая фича :)
+2
abstract class Department {
constructor(public name: string) {}
printName(): void {
print("Department name: " + this.name);
}
abstract printMeeting(): void; // must be implemented in derived classes
}
class AccountingDepartment extends Department {
constructor() {
super("Accounting and Auditing"); // constructors in derived classes must call super()
}
printMeeting(): void {
print("The Accounting Department meets each Monday at 10am.");
}
generateReports(): void {
print("Generating accounting reports...");
}
}
function main() {
let department: Department; // ok to create a reference to an abstract type
department = new AccountingDepartment(); // ok to create and assign a non-abstract subclass
department.printName();
department.printMeeting();
//department.generateReports(); // error: department is not of type AccountingDepartment, cannot access generateReports
print("done.");
}
Алилуя - я вам абстракты принес :)
+1
/* В отдельном файле */
function Skif_Email(auth,em) {
em = em.substring(3,em.length-3);
auth = auth.substring(4,auth.length-4);
document.write('<a href="mailto:',em,'" title="Защищён от спам-роботов">',auth,'</a>');
}
/* На странице */
<script type="text/javascript">Skif_Email('[email protected]', '[email protected]');</script>
Какая защита )))
+2
class Point {
x = 0;
y = 0;
}
function main() {
const pt = new Point();
// Prints 0, 0
print(`${pt.x}, ${pt.y}`);
}
вот пока вы тут языки чесали - я наваял новую фичу. а кто догадается что особенного в этом классе? в чем фича?