In the Coffeescript–ngcomponent package of the previous angular, we talked about Coffeescript's small language, discarding the dross ("pit") part of JavaScript, And bring the pristine parts of JavaScript to dripping. Although I prefer the ES6 + Babel or typescript this kind of distinctive features of JavaScript syntax. But Coffeescript is also a good JavaScript extension language, especially in the Ruby com
Please note that this article is just my prejudice, and I am trying to understand the rationale for writing JavaScript code with compilers such as Coffeescript or typescript. Statically compiled, strongly typed languages and frameworks, I have these popular, rich backgrounds. My last job was to use typescript because I had to use it. It was a time of unhappiness, and I would leave for it.I am fortunate to have freed myself from this dilemma and burden
Have you noticed that you can now write the script using Coffeescript directly on the RUNJS, using less CSS to write the style.
Let's look at a demo code:
Coffeescript:
# Assignment:
Number = 42
opposite = True
# Conditions:
Number = -42 if opposite
# functions:
Square = (x)-> x * x
# Arrays:
list = [1, 2, 3, 4, 5]
# Objects:
Math =
Root:Math.sqrt
Square:square
Coffeescript----> Install node. js----> Installation Coffeescript Statement:Note: There is no semicolon, the statement ends with a new line; multiple statements written to the same row require semicolons to denote the end of a statement (not commonly used);Continuation to the next line by adding \ Representation statements at the end of a row; Variable:Unlike JS, coff
install Coffeescript in node. js1. My node. JS installation directory2.node.js Global Module Directory 3.node.js installation Coffeescript1 npm install-g coffee-scriptAt this point node. JS has been installed in the Coffeescript compiler, but I encountered a second installation problem, is the-w parameter will be error, Error:watch einval I in the first installation, did not encounter any problems, but at t
Start to see
The code is as follows
Copy Code
Run = (A, b)-> # define the Run functionCode hearRun 1, 2 # Pass parameters 1, 2 to the Run function and execute, omitting the parenthesesRun (1, 2) # Pass parameters 1, 2 to the Run function and execute, with parentheses
Of course, you can also change the parameters of the line to write, such as:
The code is as follows
Copy Code
Run 1,2Run 1, 2Run (1,2)Run (1, 2)
As long a
For example, write the coffee file in the coffee/controller/folder, create a new Js/controller folder, use the grunt to run the project, will automatically compile coffee to the corresponding JS folder.Module.exports = function (grunt) {//project configuration information. Grunt.initconfig ({pkg:grunt.file.readJSON (' Package.json '), Jshint: {options: {jshintrc: '. Jshintrc ') ,//Eqeqeq:true,//Tradiling:true, ignores: [' Node_modules/**/*.js ']}, all: [' **/*.js ' ]}, coffee:{compile: {options:
CoffeeScript demo, coffeescriptdemo# Coffee-script.js resolution xx. coffee script can be embedded directly in the browser, but it is not recommended to use it in real time, coffee-script.js: http://coffeescript.org/extras/coffee-script.js# To locally install coffee, compile xx. coffee into xx. js. Command: coffee-c xx. coffee# VARIABLESMyVar = 1# ArrayMyArray = [1, 2, 3, 4, 5]# ObjectLeader =Name: "wj"Age: 25Alert (leader. name)# Function if x = null
Sublime Text compilation CoffeeScript error solution, sublimecoffeescript
Try todaySublime TextCompileCoffeeScript The CoffeeScript plug-in is installed first, and then a CoffeeScript is added to the compiler, but an error is prompted when trying to compile the code, and then the Internet looks for a solution without solution... So I tried to change the SublimeT
Coffeescript is a little language that compiles into Javascript. The Code compiles one-to-one into the equivalent JS, and there is not InterpretationAt runtime. You can use any existing JavaScript library seamlessly (and vice-versa ).
The syntax of coffeescript is too red by ruby and python, and implements extends features from those two ages. This introduction references the little bookOn
About Sonarlanguage is what dongdong, here is not described, if you are interested in it, please go to the previous essay open Source: angularjs example--sonar Project use language map. Here is a recent practice version of learning Coffeescript.
Coffeescript is a concise, JavaScript-based preprocessor language that can be statically compiled into JavaScript, which is primarily influenced by Ruby and Python
Two days ago looked at Coffeescript, based on node. JS, incidentally Configure a node environment bar, toss for a long time1. Download the MSI installation Environment from node. jsAfter the installation is complete open the installation directory, you can see a node.exe open can be executed in the JS code, similar to the chrome console, attention is not executed here node command! All of the following execution environments are cmd.Open cmd, input no
More and more people begin to use less and other pre-processor methods to write CSS and JavaScript. The popular ones are less, sass, and coffeescript. LessCodeIt cannot be executed directly in the browser. In the end, it still needs to be compiled into CSS or Js. Their syntax is great, but their compilation methods are not flexible enough. Basically, the official website only provides the command line method for file compilation. Less can also embed a
In terms of inheritance, js is still weak. It is found that constructor and initialize are divided during inheritance. The relationship between the two is not described in online articles. After reading the source code, we can see the difference between the two. First, I used coffeescript to implement js inheritance. A problem was found during the process. By using Backb... SyntaxHighlighter.
In terms of inheritance, js is still weak. It is found that
Koala v1.3.0 has been released. You are welcome to download and use it.
: Http://koala-app.com/index-zh.html
Update description:
New Feature: allows you to directly use the compiledProgram.New Function: Right-click the menu and add the "open file" option.Set the default output path to the CSS/JS directory under the same directory as the project directory, such as./less->./CSS.Fixed the bug: A compilation error occurred when the directory contains spaces.Fixed the bug: failed to add a project
Example
A = 5b =->Return 5
Compiled JavaScript code:
(function () {var a, B;
A = 5;
b = function () {return 5;};). Call (this);
But we may have the need to define global variables, so Coffeescript still provides a declarative way to not exterminate global variables:
If you are like "to" create top-level variables for "Other scripts", attach them as properties on Windows, or on the Expor TS object in Commonjs. The existential operator (covered
Reply content:Basic syntax
Coding techniques, coding specifications
Various functions
Various PHP modules
Learn a CMS or two-time development
Learn about Pdo,ado, data-driven layers, and learn MySQL on the go
Error mechanism
Object oriented
Use a framework to help develop
Magic method
Design Patterns
Reflection
Write all kinds of tools, drivers.
Write a small fra
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.