เมื่อวันก่อนผมอ่าน Twitter แล้วมันก็เด้งบทความเกี่ยว JS++ มาให้อ่าน http://sdtimes.com/the-case-for-js-plus-plus/ ซึ่งเนื้อหาหลักๆที่ผมเข้าใจคือ ทางผู้พัฒนาต้องการอุดช่องว่างของ JavaScript ซึ่งหลักๆก็คือเรื่อง Type และ Object Oriented ซึ่งโปรเจคแนวนี้ก็มีเยอะมากในวงการเช่น Dart หรือ TypeScript
ส่วน JS++ เองนั้นผู้พัฒนาคือ บริษัท Onux ซึ่งมี Official Site อยู่ที่ https://www.onux.com/jspp/
Platform ที่ทาง JS++ รองรับในตอนนี้คือ Windows กับ Linux เท่านั้น และในปัจจุบันนี้ อยู่ที่ Version 0.4.1 ซึ่งเป็น Early Access Preview อยู่
เมื่อ Install เสร็จก็จะได้ไฟล์ประมาณนี้
ลองเช็ค version ดูด้วย js++ –version ก็ได้เป็น 0.4.1
หลักการทำงานของ JS++ นั้นก็คือเราต้องเขียน Code ด้วย Systax ของ JS++ จากนั้นทำการ Compile ให้ออกมาเป็นไฟล์ .js ที่ Browser เข้าใจ
ที่นี้ลอง Hello World ง่ายๆ ด้วยการสร้างไฟล์ test.jspp
external document; document.write("Hello World!");
ลอง Compile กันดูครับ
ไฟล์ที่ออกมาก็หน้าตาแบบนี้ครับ ซึ่งเป็นสิ่งที่ js เข้าใจ
// Compiled with JS++ v.0.4.1 !function(){document.write("Hello World!");}();
งั้นลองกับ Node.js หน่อยดีกว่า
import Convert; external require; external http = require("http"); external console; string hostname = '127.0.0.1'; int port = 1337; http.createServer(void(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); }).listen(port, hostname, void() { console.log("Server running at http://" + hostname + ":" + Convert.toString(port) + "/"); });
Compile มาได้แบบนี้ (ดีจริง minify มาให้พร้อม)
// Compiled with JS++ v.0.4.1 !function(){var http=require("http");var hostname='127.0.0.1';var port=1337|0;http.createServer(function(req,res){res.writeHead(200,{'Content-Type':'text/plain'});res.end('Hello World\n');}).listen(port,hostname,function(){console.log("Server running at http://"+hostname+":"+(port+"")+"/");});}();
ลองรันดูก็ WORK ดีครับ
ที่นี้ผมลองเอา Code จากหน้า Offical Page ที่มี Class มาลองอีกทีครับ ปรากฏว่า Compile Error เพราะหา Class ไม่เจอ…!@#$
สรุป…ผมว่าสำหรับ Build นี้อาจจะยังไม่ถึงเวลาของ JS++ ในการใช้งานจริงครับ และผมก็คิดว่าทางตัวโปรเจคนี้ก็ยังความท้าทายในการเป็น Framework ที่ฮิตอยู่คือ
- ไม่เป็น Open Source
- ไม่มี บ.ยักษ์ใหญ่ช่วยหนุน
- ไม่มี Roadmap ชัดเจนสำหรับ Release ถัดๆไป
ผมคิดว่า ณ วันนี้ถ้าต้องการมองหาทางเลือกอื่นในการพัฒนา App หรือ Service โดยไม่ต้องใช้ JavaScript ตรงๆ ลองมอง TypeScript หรือ Dart ดีกว่าครับ…(ส่วนตัวตอนนี้ศึกษา TypeScript ครับ)