FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/examples/objects.js at develop · ThinkLib/mathjs · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ThinkLib
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
examples
/
objects.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (28 loc) · 1.05 KB
Breadcrumbs
mathjs
/
examples
/
objects.js
Copy path
File metadata and controls
36 lines (28 loc) · 1.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// objects
// load math.js (using node.js)
var
math
=
require
(
'../index'
)
;
// create an object. Keys can be symbols or strings
print
(
math
.
eval
(
'{x: 2 + 1, y: 4}'
)
)
;
// {"x": 3, "y": 4}
print
(
math
.
eval
(
'{"name": "John"}'
)
)
;
// {"name": "John"}
// create an object containing an object
print
(
math
.
eval
(
'{a: 2, b: {c: 3, d: 4}}'
)
)
;
// {"a": 2, "b": {"c": 3, "d": 4}}
var
scope
=
{
obj
:
{
prop
:
42
}
}
;
// retrieve properties using dot notation or bracket notation
print
(
math
.
eval
(
'obj.prop'
,
scope
)
)
;
// 42
print
(
math
.
eval
(
'obj["prop"]'
,
scope
)
)
;
// 42
// set properties (returns the whole object, not the property value!)
print
(
math
.
eval
(
'obj.prop = 43'
,
scope
)
)
;
// {"prop": 43}
print
(
math
.
eval
(
'obj["prop"] = 43'
,
scope
)
)
;
// {"prop": 43}
print
(
scope
.
obj
)
;
// {"prop": 43}
/**
* Helper function to output a value in the console. Value will be formatted.
*
@param
{
*
} value
*/
function
print
(
value
)
{
var
precision
=
14
;
console
.
log
(
math
.
format
(
value
,
precision
)
)
;
}
Back
|
FazBrowse Home
|
New Git URL