Skip to content

Commit

Permalink
Merge cbec905 into 797092c
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalsodani authored Jan 15, 2021
2 parents 797092c + cbec905 commit 2ce1b54
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions boa/examples/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use boa::{
// We derive `Debug`, `Trace` and `Finalize`, It automatically implements `NativeObject`
// so we can pass it an object in JavaScript.
//
// The fields of the sturct are not accesable by JavaScript unless accessors are created for them.
// The fields of the struct are not accessible by JavaScript unless accessors are created for them.
/// This Represents a Person.
#[derive(Debug, Trace, Finalize)]
struct Person {
Expand Down Expand Up @@ -58,20 +58,20 @@ impl Class for Person {

// This is what is called when we do `new Person()`
fn constructor(_this: &Value, args: &[Value], context: &mut Context) -> Result<Self> {
// we get the first arguemnt of undefined if the first one is unavalable and call `to_string`.
// We get the first argument. If it is unavailable we get `undefined`. And, then call `to_string()`.
//
// This is equivalent to `String(arg)`.
let name = args
.get(0)
.cloned()
.unwrap_or_default()
.to_string(context)?;
// we get the second arguemnt of undefined if the first one is unavalable and call `to_u32`.
// We get the second argument. If it is unavailable we get `undefined`. And, then call `to_u32`.
//
// This is equivalent to `arg | 0`.
let age = args.get(1).cloned().unwrap_or_default().to_u32(context)?;

// we construct the the native struct `Person`
// we construct the native struct `Person`
let person = Person {
name: name.to_string(),
age,
Expand All @@ -86,7 +86,7 @@ impl Class for Person {
//
// This function is added to `Person.prototype.sayHello()`
class.method("sayHello", 0, Self::say_hello);
// we add a static mathod `is`, and here we use a closure, but it must be converible
// we add a static mathod `is`, and here we use a closure, but it must be convertible
// to a NativeFunction. it must not contain state, if it does it will give a compilation error.
//
// This function is added to `Person.is()`
Expand All @@ -102,11 +102,11 @@ impl Class for Person {
Ok(false.into()) // otherwise `false`.
});

// Add a inherited property with the value `10`, with deafault attribute.
// Add a inherited property with the value `10`, with default attribute.
// (`READONLY, NON_ENUMERABLE, PERMANENT).
class.property("inheritedProperty", 10, Attribute::default());

// Add a static property with the value `"Im a static property"`, with deafault attribute.
// Add a static property with the value `"Im a static property"`, with default attribute.
// (`WRITABLE, ENUMERABLE, PERMANENT`).
class.static_property(
"staticProperty",
Expand Down

0 comments on commit 2ce1b54

Please sign in to comment.