Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- javascript



  Start to work with rollup.js to pack JS files

rollup.js is a module bundler for JavaScript. It compiles small piece of JavaScript modules spreading in different files into a single larger standardized ES code file. This post will show some entry level usage for this library. Introduction Normally a bundler tool would compile a few small JavaScript files into a single JavaScript so that web browser can read, parse and render it properly. A bundler tool may be needed because of a few reasons: Some early stage browsers don't understand module...

   ROLLUP.JS,COMMONJS,ES MODULE,BUNDLE,WEBPACK     2022-06-12 00:00:14

  Three ways to define class in JavaScript

In object oriented programming, class is the template of object, it defines the properties and methods of a group of objects. Unfortunately, JavaScript doesn't support class, but we can have some workarounds to simulate class.1. Constructor functionThis is the classical approach, it is also the approach mentioned in many text books. It uses the constructor function to simulate class and it uses the keyword this to represent the object internally.function Cat() {  this.name = "Kelly...

   JavaScript,Class,Method,Private,Inheritance     2012-07-09 11:59:51

  Node.js: Five Things Every PHP Developer Should Know

I recently started working on a few Node.js applications. Coming most recently from PHP (and Drupal in particular), I found the transition to Node.js to be surprisingly easy. Pleasurable, in fact. But I had to learn to think differently about a few things. Below I list the five things I think every PHP developer should know about Node.js. 1. Node.js Is Built On Chrome's JavaScript Engine Google's browser, Chrome, has a notoriously fast JavaScript engine called V8. And this JavaScript engine ...

   PHP,Node.js,Developer,Feature     2012-02-09 07:37:48

  Regular expression to get html meta description

When we need to process a HTML page source code, we often need to retrieve the meta description of the page besides the links in the page. This description is usually located in <meta> tag of a HTML page. The meta description is very useful for search engine index. How can we retrieve the meta description? If we use a regular expression, we can easily get the meta description. In JavaScript, the regular expression looks like : var pattern = /<meta.*?name="description".*?content="(.*?)"....

   Regular expression,meta description,HTML,JavaScript     2012-07-03 10:09:20

  Commonly used AJAX frameworks

Have you ever wondered to design your website like desktop applications? Fortunately, with AJAX we can achieve this. By using AJAX, we no need to refresh the whole page when we just want to update a portion of a website such as the weather information or news panel. This makes our web apps look like desktop applications and bring good user experience to our visitors. You can create an XMLHttpRequest object every time when you want to initialize an AJAX call, unfortunately you may need repeat eve...

   AJAX,framework,jQuery,Dojo,YUI     2012-06-27 04:40:05

  Which programming language should I learn first?

Recently I saw somebody asked a question in a forum, the question is "Which programming language should I learn first?". Then someone answered this question. His answer:Depends. To program in an expressive and powerful language: PythonTo get a website up quickly: PHPTo mingle with programmers who call themselves “rockstars”: Ruby.To really learn to program: C.To achieve enlightenment: Scheme.To feel depressed: SQLTo drop a chromosome: Microsoft Visual BasicTo get a guaranteed, m...

   Programming language,Learn,JavaScript,C     2012-04-29 02:59:17

  JavaScript-style object literals in PHP

The object literal notation in JavaScript looks like: var fido = {name: "Fido", barks: true}; or var fido = {}; fido.name = "Fido"; fido.barks = true; From assoc arrays to objects In PHP you would call that an associative array. $fido = array( 'name' => "Fido", 'barks' => true ); And you can easily make it an object too: $fido = (object)$fido; echo gettype($fido); // "object" Or if you want to start with a blank object and add stuff to it: $fido = (object)array(); or $fido...

   PHP,JavaScript,Object,Function call,Self vs this     2011-11-30 11:11:45

  Run JavaScript in GoLang

In some cases, there might be some JavaScript code needs to be ran in a GoLang project. Fortunately, there are a few libraries which support running JavaScript in GoLang. The most famous one would be v8. This is a Go API for the famous v8 JavaScript engine originally developed for the Chrominum project and the foundation of NodeJS. In this post, we will show some simple steps to get v8 working in a GoLang program on MacOS. First you need to install the package so that you can import it. Run...

   GOLANG,JAVASCRIPT,V8     2019-05-16 07:40:38

  Using JavaScript to operate clipboard

Browsers allow JavaScript to read and write data on clipboard. Generally script should not modify user's clipboard to avoid impacting user expectation, but there are cases where this can indeed bring convenience to users. For example, for some code snippet, user can copy it to clipboard with one click instead of select and copy manually. There are three options for clipboard operation provided in JavaScript/browser: document.execCommand() Asynchronous Clipboard API copy and paste events This p...

   JAVASCRIPT,CLIPBOARD,NAVIGATOR.CLIPBOARD     2021-01-23 23:23:34

  Remove duplicated elements in JavaScript array

During interviews, one frequent question asked would be something like how to remove duplicated elements in a JavaScript array and how many different ways you can think of. The interviewee would also be asked to write the code down. In real applications, normally front end would not need to handle this case since normally it would be done by backend, but still it's necessary for front end developers to know different ways of doing this. This post will share some of the common ways to remove dupl...

   JAVASCRIPT,ARRAY,DUPLICATED ELEMENT     2018-09-21 22:32:10