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

SEARCH KEYWORD -- Obj



  malloc/free and new/delete in C++

malloc and free are C++/C language standard library functions, while new/delete are operator of C++. They can be used to allocate dynamic memory and free memory in C++ programs malloc/free can not meet the requirements of dynamic objects creation. Object needs to call the constructor to initialize the object when creating, the object needs to call the destructor before it is destroyed  Since malloc() and free() are library functions rather than operators, the compiler has no control permiss...

   C++,memory,malloc,free,new,delete     2012-06-20 06:52:09

  Deep clone of JavaScript object

In JavaScript world, it's frequently seen object clone. Normally when creating a clone of an object, it's only the reference being cloned but not all contents. In some scenarioes, it's desired to clone all the content instead of just the reference such that any change made to the cloned object will not change the original object. Differences between shallow clone and deep clone can be as simple as: Shallow clone : Only the object reference is cloned but not the content Deep clone : Clone all co...

   JAAVSCRIPT,DEEP CLONE,DEEP COPY,SHALLOW CLONE,SHALLOW COPY     2016-10-31 00:27:24

  Can two new objects point to the same memory address in GoLang?

Do you have any idea what the output will be for below GoLang snippet? package main import ( "fmt" ) type obj struct{} func main() { a := &obj{} fmt.Printf("%p\n", a) c := &obj{} fmt.Printf("%p\n", c) fmt.Println(a == c) } Many people would think that a and c are two different object instances which have different memory addresses. Hence a == c will be false. But if you try to run the above program, you would see below output 0x5781c8 0x5781c8 true To get to know the reason wh...

   GO,GOLANG,VARIABLE ESCAPE,ZEROBASE     2019-04-06 01:19:52

  Using JSON in PHP

Currently JSON has become one of the most popular data exchange formats. Many website APIs support it. Since PHP 5.2, PHP provides json_encode() and json_decode() method to handle JSON encoding and decoding.1. json_encode()This function is used to transform array and objects to JSON format. First let's look one array example.        $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);   echo json_encode($arr);the result is{"a":1,"b"...

   JSON,PHP,json_decode(0,json_encode()     2012-05-06 06:04:42

  JavaScript: Passing by Value or by Reference

In JavaScript, we have functions and we have arguments that we pass into those functions. But how JavaScript handles what you’re passing in is not always clear. When you start getting into object-oriented development, you may find yourself perplexed over why you have access to values sometimes but not other times. When passing in a primitive type variable like a string or a number, the value is passed in by value. This means that any changes to that variable while in the function are com...

   JavaScript,Function,Pass by reference,Pa     2011-07-28 11:05:25

  jsonSerialize() in extended class

Since PHP 5.4.0, there is a convenient interface JsonSerializable which can be used to indicate that a PHP object can be serialized to JSON object. It has only one method which should be implemented by any class which implements this interface. The method is named jsonSerialize(). It's really easy to serialize an object to JSON object. Here is one example: <?php class ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; ...

   JSON,jsonSerialize,Inheritance,extends     2014-07-26 05:54:00

  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

  Why localStorage only allows to store string values

localStorage allows data to be stored in browsers across sessions, the data will be there even though the session is expired. It is frequently used to store static data so that they can be loaded when needed. But as per spec, it says that the keys and the values are always strings (note that, as with objects, integer keys will be automatically converted to strings). Why cannot store the object as it is? Take a look at an example: var str = "test"; localStorage.setItem("str", str); cons...

   JAVASCRIPT,LOCALSTORAGE     2020-04-05 00:54:29

  ECMAScript 5 Objects and Properties

ECMAScript 5 is on its way. Rising from the ashes of ECMAScript 4, which got scaled way back and became ECMAScript 3.1, which was then re-named ECMAScript 5 (more details)- comes a new layer of functionality built on top of our lovable ECMAScript 3. Update: I've posted more details on ECMAScript 5 Strict Mode, JSON, and More. There are a few new APIs included in the specification but the most interesting functionality comes into play in the Object/Property code. This new code gives you th...

   ECMAScript,Object,Property     2012-01-29 04:38:50

  Let's talk about JSON.stringify()

JSON has been used in lots of places to exchange data among different services/systems. Nowadays all mainstream programming languages have built-in library support of JSON data parse and stringify. In this post, let's talk about JSON.stringify() in JavaScript. Let's first take a small example of Object conversion handling. There is a requirement to convert below object const todayILearn = { _id: 1, content: '今天学习 JSON.stringify(),我很开心!', ...

   JAVASCIPT,JSON,JSON.STRINGIFY     2020-02-22 04:25:08