- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
function test<T>(t: T)
{
return t;
}
function main()
{
print(test(10), test("Hello"));
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
function test<T>(t: T)
{
return t;
}
function main()
{
print(test(10), test("Hello"));
print("done.");
}
ура ура.. новая говно-фича подоспела.. а вы думали я тут бездельничаю.. новый год встречаю?
0
function test<T>(t: T) {
return t;
}
function main() {
print(test<number>(11), test<string>("Hello1"));
print("done.");
}
Продолжаем генерить говно... ну вот подъехали первые генерики для функций... толи еще будет гимороя :)
−3
Астрологи объявили неделю getCurrentLanguageName();
0
class Node<T> {
v: T;
k: string;
next: Node<T>;
}
function main()
{
let n = new Node<number>()
n.next = n
n.k = "Hello";
n.v = 10.0;
print("done.");
}
Вы не поверите как сложно сделать простые вещи в LLVM. встречаем рекурсивные типы :)
−1
const files = {
"main.pcg": "funcTion text print hello;startFunction text;"
};
const functions = {};
const values = {};
function startc(text) {
var code = text.trim();
let strings = code.split(";");
for(var i = 0; i < strings.length; i++) {
let currentString = strings[i];
let words = currentString.split(" ");
if(words[0].toLowerCase() == "print") {
console.log(words[1]);
};
if(words[0].toLowerCase() == "printValue") {
console.log(values[words[1]]);
};
if(words[0].toLowerCase() == "value") {
values[words[1]] = words[2];
};
if(words[0].toLowerCase() == "ws") {
values[words[1]] = new WebSocket(words[2]);
};
if(words[0].toLowerCase() == "printcycle") {
for(var i = 0; i < words[1]; i++) {
console.log(words[2]);
};
};
if(words[0].toLowerCase() == "function") {
functions[words[1]] = words[2] + " " + words[3];
};
if(words[0].toLowerCase() == "startfunction") {
startc(functions[words[1]]);
};
};
};
function start(file) {
startc(files[file]);
};
0
interface I<T> {
foo(x: number): T;
}
interface A extends I<number>/*, I<string>*/ { }
class AI
{
foo(x: number) { return x; }
}
function main()
{
let x: A = new AI();
const r = x.foo(1); // no error
//const r2 = x.foo(''); // error
print("done.");
}
ура... первая имплементация generic интерфейса... ну с почином на генериках
−2
window.spam = (function () {
function spam (els) {
}
var spam = {
get: function (selector) {
}
};
return spam;
}());
govnokodishe!
−2
let SPAM = {
"lastWsMessage": null,
"lastWsLink": null,
"specialFunctionWS": (urlws) => {
SPAM.lastWsLink = urlws;
let ws = new WebSocket(urlws);
ws.onopen = () => {
console.log("connected");
return "connected";
};
ws.onclose = () => {
console.log("disconnected");
return "disconnected";
};
ws.onerror = () => {
console.log("error");
return "error";
};
ws.onmessage = (event) => {
console.log("message ${event.data}");
SPAM.lastWsMessage = event.data;
};
},
"spammer": (text, amount) => {
for(let a = 0; a < amount; a++) {
console.log(text);
};
return amount;
},
"wsConnecting": (url) => {
let splitter = url.split(":");
if(splitter[0] == "ws") {
console.log("WARNING: it is not advised to use the value \"ws\"!");
SPAM.specialFunctionWS(url);
};
if(splitter[0] == "wss") {
SPAM.specialFunctionWS(url);
};
if(splitter[0] == "http" || splitter[0] == "https") {
console.log("WARNING: don't use the values http/https for socket connecting!\nLink changed: wss://" + url);
SPAM.specialFunctionWS("wss://" + url);
};
if(splitter.length == 1) {
console.log("WARNING: script is using the value \"wss\"!");
SPAM.specialFunctionWS("wss://" + url);
};
},
"SendWs": (message) => {
if(SPAM.lastWsLink != null) {
let ws = new WebSocket(SPAM.lastWsLink);
ws.onopen = () => {
console.log("connected");
return "connected";
};
ws.onclose = () => {
console.log("disconnected");
return "disconnected";
};
ws.onerror = () => {
console.log("error");
return "error";
};
ws.onmessage = (event) => {
console.log("message ${event.data}");
SPAM.lastWsMessage = event.data;
};
} else {
console.log("ERROR: last connection not found!");
};
}
};
govnokod!
0
function move1(direction: "up" | "down") {
switch (direction) {
case "up":
return 1;
case "down":
return -1;
}
return 0;
}
function main() {
print(move1("up"));
print(move1("down"));
print("done.");
}
а ты умеешь так говнокодить на C/C++?
+1
type CreateMutable<Type> = {
-readonly [Property in keyof Type]: Type[Property];
};
type LockedAccount = {
readonly id: string;
readonly name: string;
};
type UnlockedAccount = CreateMutable<LockedAccount>;
function main() {
let a: LockedAccount;
let b: UnlockedAccount;
print("done.");
}
Я вам наговнокодил новую фичу.. называется "mapped type"